可以选择在http{ }中设置:client_max_body_size 20m;
也可以选择在server{ }中设置:client_max_body_size 20m;
还可以选择在location{ }中设置:client_max_body_size 20m;
三者到区别是:http{} 中控制着所有nginx收到的请求。而报文大小限制设置在server{}中,则控制该server收到的请求报文大小,同理,如果配置在location中,则报文大小限制,只对匹配了location 路由规则的请求生效。
配置反向代理
server { listen 80; server_name myproxy; location / { proxy_pass http://47.104.211.203:83; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
使用include配置
在nginx.conf中加入
http的括号里面 include host/*.conf;
路径是在conf文件下新增host文件里面存放多个域名的配置:如下shop.conf
server { listen 80; server_name shop.xxx.com; proxy_set_header Host $host:$server_port; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; location / { proxy_set_header Host $host:$server_port; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://101.xxx.182.5:8084; } }