Nginx 413 Request Entity Too Large

用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;
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值