내 고객이 XHR2 양식 데이터(및 CORS를 사용한 도메인 간 요청)를 사용하는 양식 POST를 통해 원격 nginx 웹 서버에 파일을 업로드하려고 합니다. 업로드 도중 웹 서버는 408을 반환하고 결과적으로 Ajax 오류 처리기가 처리를 중단합니다. 파일 크기는 20-120MB 범위입니다. 일부 파일 업로드에 대한 액세스 로그는 다음과 같습니다(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"
IE 대신 Chrome을 사용하면 파일이 완벽하게 업로드되는 경우도 있고 그 반대인 경우도 있지만 대부분의 경우 두 브라우저 모두 작동하지 않습니다.
나는 nginx wiki를 읽었으며 408 오류와 관련된 유일한 두 가지 설정은 client_body_timeout
및 client_header_timeout
. 이 두 지시어의 의미를 이해하는 데 어려움을 겪고 있습니다. 둘 다 180초로 늘렸지만 문제가 지속됩니다. 나는 그에게 연결 속도가 느린지 물었고 그는 2.5mbps의 속도를 가지고 있다고 말했습니다. 이는 요청 헤더를 완전히 수신할 수 있을 만큼 충분히 빨라야 합니다.위키, "읽기 단계"가 무엇인지 등). 이전에 다른 고객으로부터 서버에 1GB의 업로드를 성공적으로 받은 적이 있는데, 일반적으로 완료하는 데 약 1시간이 걸립니다.
결국 고객으로부터 성공적으로 받은 문제 파일에 대해 다양한 브라우저에서 동일한 파일을 업로드해 보았는데 완벽하게 작동했습니다.
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/*;
}
업로드 서버 구성:
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;
}
}
성공적인 업로드를 방해하고 성가신 408 오류를 일으킬 수 있는 구성 요소가 구성에 있습니까? 이 문제에 대한 오류 로그에는 아무 것도 언급되어 있지 않습니다.
reload
참고: nginx 구성을 변경할 때만 사용했습니다 . 우리는 이를 방지하려고 노력하고 있지만 restart
구성 변경 사항이 완전히 적용되기 위해 필요한 경우 그렇게 할 것입니다.