我的一个客户正试图通过使用XHR2表单数据(以及CORS的跨域请求)的表单POST将file upload到我们的远程nginx web服务器。 在上传期间,networking服务器返回一个408,结果ajaxerror handling程序停止处理。 这些文件在20-120MB的范围内。 一些file upload的访问日志如下(他已经在Chrome 31和IE11上试过):
[24/Dec/2013:16:44:18 -0500] "OPTIONS / HTTP/1.1" 200 0 "http://www.example.com/files/upload" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" [24/Dec/2013:16:47:50 -0500] "POST / HTTP/1.1" 408 0 "http://www.example.com/files/upload" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36" ... [27/Dec/2013:01:23:51 -0500] "OPTIONS / HTTP/1.1" 200 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko" [27/Dec/2013:01:33:11 -0500] "POST / HTTP/1.1" 408 0 "http://www.example.com/files/upload" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"
有时候,用Chrome浏览器代替IE浏览器,file upload会非常好,有时反过来,但大多数情况下浏览器都不会为他工作。
我一直在阅读nginx wiki,与408错误相关的唯一两个设置是client_body_timeout
和client_body_timeout
。 我很难理解这两个指令的含义。 我增加到180秒,但问题依然存在。 我问他是否有一个缓慢的连接,他说,他有2.5 mbps的速度,这应该是足够快,完全收到请求标题(但是,我们不确定这两个指令是什么意思,根据维基 ,这样作为“读取步骤”)。 我们已经成功地从其他客户那里获得了1GB的上传到我们的服务器,通常需要一个小时左右才能完成。
对于我们最终成功从客户收到的有问题的文件,我们尝试在各种浏览器中上传相同的文件,并且完美地工作。
我读过使用SSL可能导致超时,但服务器没有启用SSL,我们只使用http。
我们的nginx.conf:
user www-data; worker_processes auto; pid /run/nginx.pid; events { worker_connections 5000; # multi_accept on; } http { ## # Basic Settings ## sendfile on; tcp_nopush on; tcp_nodelay off; keepalive_timeout 25; # Increase client/head body_timeout to prevent 408's for slow Internet connections?? client_header_timeout 180; client_body_timeout 180; types_hash_max_size 2048; server_tokens off; # server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; default_type application/octet-stream; ## # Logging Settings ## access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; ## # Gzip Settings ## gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 5; gzip_min_length 256; gzip_types application/atom+xml text/javascript application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component; # Increase FastCGI buffers fastcgi_read_timeout 1500; fastcgi_buffers 8 16K; fastcgi_buffer_size 32K; ## # Virtual Host Configs ## include /etc/nginx/conf.d/*.conf; include /etc/nginx/sites-enabled/*; }
我们的上传服务器configuration
server { listen 80; server_name upload.example.com; root /var/www/releases/latest/_UPLOAD/public; # remove trailing slash, that throws ZF router if (!-d $request_filename) { rewrite ^/(.*)/$ /$1 permanent; } # 1.2G upload limit + 10M for post data (which is extremely liberal) client_max_body_size 1210M; client_body_buffer_size 4M; proxy_max_temp_file_size 0; location = /favicon.ico { access_log off; log_not_found off; } location = /apple-touch-icon.png { access_log off; log_not_found off; } location / { # This is for AJAX file uploads... need to set CORS headers if ($request_method = OPTIONS ) { add_header Access-Control-Allow-Origin '$scheme://www.example.com'; add_header Access-Control-Allow-Methods 'POST, OPTIONS'; add_header Access-Control-Allow-Headers 'X-Requested-With, Content-Type, Content-Range, Content-Disposition'; return 200; } try_files $uri $uri/ /index.php?$args; index index.php index.html index.htm; } location ~ \.php$ { try_files $uri $uri/ /index.php?$args; index index.php index.html index.htm; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/releases/latest/_UPLOAD/public$fastcgi_script_name; fastcgi_param APPLICATION_ENV production; fastcgi_param PATH /usr/bin:/bin:/usr/sbin:/sbin; fastcgi_intercept_errors on; include fastcgi_params; } error_page 403 =404 /404.html; error_page 404 /404.html; location = /404.html { root /var/www/releases/latest/_UPLOAD/public; internal; } error_page 500 502 503 504 = /50x.html; location = /50x.html { root /var/www/releases/latest/_UPLOAD/public; internal; } }
configuration中是否有可能阻止成功上传并导致这些讨厌的408错误? 错误日志中没有提到这个问题。
注意:当我们对nginxconfiguration进行更改时,我们只使用了reload
。 我们正在尝试避免restart
但是如果需要我们的configuration更改才能完全启动,那么我们将执行此操作。