用Nginx反向代理服务器,进行附件相关的操作时,当文件大小超过1M,会出现413 Request Entity Too Large,这是由于Nginx客户端默认的最大请求体只有1M。
修改Nginx请求的内容方式如下:
1、设置location请求体大小
client_max_body_size 300m;
设置后重启Nginx服务器。
2、数据量大,网速慢,超过一分钟时,会出现 Gateway 504 Time out
是由于Nginx默认的代理时长为1分钟,超出一分钟就会报错
在location中设置代理时长
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
3、完整的Nginx配置如下:
server {
listen 30001 ;
server_name 192.168.1.203;
location / {
proxy_pass http://192.168.1.203:31000;
client_max_body_size 300m;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "$http_origin";
add_header Access-Control-Allow-Methods "POST, GET, PUT, OPTIONS, DELETE";
add_header Access-Control-Max-Age "3600";
add_header Access-Control-Allow-Headers "*";
add_header Access-Control-Allow-Credentials "true";
add_header Content-Length 0;
add_header Content-Type text/plain;
return 200;
}
add_header 'Access-Control-Allow-Origin' '$http_origin';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET,PUT,POST,DELETE,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Content-Type,*';
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Real-Source-IP $http_real_source_ip;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}