Nginx配置,413 Request Entity Too Large错误解决
今天有同事找我,说图片上传之后,不知道去哪里了。分析了一下问题,找到原因之后做了处理,这里简要记录一下。
问题原因:
1.首先后台log并无错误信息;
2.捡查了一下浏览器,发现network中有报错,413 Request Entity Too Large,但前台未报错。
解决办法:
1.备份Nginx配置文件;(个人习惯,免得修改之后,如果需要还原,忘记原来的配置)
2.查看当前Nginx配置文件:
[root@VM_0_16_centos nginx]# cat nginx.conf | grep client_max_body_size
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
client_max_body_size 10m;
结果发现涉及到很多项目,继续查询
cat /etc/nginx/nginx.conf | grep -C 10 client_max_body_size
得到结果如下:
[root@VM_0_16_centos nginx]# cat /etc/nginx/nginx.conf | grep -C 10 client_max_body_size # Load configuration files for the default server block. #include /etc/nginx/default.d/*.conf; location ^~ /b1/ { proxy_pass http://b1_server/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; # client_max_body_size 10m; access_log /logs/nginx/access_api_b1.log main; error_log /logs/nginx/error_api_b1.log info; } location ^~ /bn/ { proxy_pass http://bn_server/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; # client_max_body_size 10m; access_log /logs/nginx/access_api_bn.log main; error_log /logs/nginx/error_api_bn.log info; } # 由于boss程序中web路径已经带/boss前缀,所以proxy_pass不能带/后缀,后续再调整,切记切记! location ^~ /boss/ { proxy_pass http://boss_server; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; # client_max_body_size 10m; access_log /logs/nginx/access_api_boss.log main; error_log /logs/nginx/error_api_boss.log info; } location ^~ /detector/ { proxy_pass http://detector_server/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; client_max_body_size 10m; access_log /logs/nginx/access_api_detector.log main; error_log /logs/nginx/error_api_detector.log info; } location ^~ /sales/ { proxy_pass http://sales_server/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; # client_max_body_size 10m; access_log /logs/nginx/access_api_sales.log main; error_log /logs/nginx/error_api_sales.log info; } location ^~ /qn/prv/ { proxy_pass http://private.haochuang.cn/; } location ^~ /qn/pub/ { -- error_log /logs/nginx/error_admin_boss.log info; } location ^~ /boss/ { proxy_pass http://boss_server; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; # client_max_body_size 10m; access_log /logs/nginx/access_api_boss.log main; error_log /logs/nginx/error_api_boss.log info; } location ^~ /stats/ { proxy_pass http://stats_server; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header Connection close; proxy_connect_timeout 5000ms; client_max_body_size 10m; access_log /logs/nginx/access_api_stats.log main; error_log /logs/nginx/error_api_stats.log info; } location ^~ /qn/prv/ { proxy_pass http://private.haochuang.cn/;
}
3.修改配置文件:
location / {
root html;
index index.html index.htm;
client_max_body_size 1000m;
}
修改client_max_body_size 配置:
server { listen 80; server_name chat.erp.360buy.com; #access_log /export/servers/nginx/logs/chat.erp.360buy.com; location / { proxy_pass http://tomcat; client_max_body_size 10m; #表示最大上传10M,需要多大设置多大。 } }
3.重新加载配置文件,并重新加载nginx:
[root@VM_0_16_centos nginx]# /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@VM_0_16_centos nginx]# /usr/sbin/nginx -s reload
4.如果还未生效,重启nginx:
[root@VM_0_16_centos nginx]# /usr/sbin/nginx -s reload
[root@VM_0_16_centos nginx]# service nginx restart
Redirecting to /bin/systemctl restart nginx.service
5.再次验证结果,结果可见,最终问题已解决。
/usr/local/nginx/sbin/nginx -t
2.重新加载nginx,nginx相关参数
[root@VM_0_16_centos nginx]# which nginx
/usr/sbin/nginx
[root@VM_0_16_centos nginx]# /usr/sbin/nginx -h
nginx version: nginx/1.12.2
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it and exit
-q : suppress non-error messages during configuration testing
-s signal : send signal to a master process: stop, quit, reopen, reload
-p prefix : set prefix path (default: /usr/share/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file
...
相关文章
- javascript中错误使用var造成undefined
- Nginx配置SSL证书时——nginx:[emerg]unknown directive ssl错误
- samba配置中常见错误收集.txt
- IIS7错误:“Web服务器被配置为不列出此目录的内容”的解决办法
- libcurl中使用curl_easy_getinfo 产生段错误分析
- 分析器错误
- Linux iptables配置错误导致ORA-12535 & ORA-12170
- eclipse配置tomcat,访问http://localhost:8080出现404错误
- maven pom插件配置 及 maven 出现错误 -source 1.5 中不支持 diamond 运算符解决办法
- 78. 浅谈 ABAP 程序运行时出现『内存耗尽』错误的问题
- SAP ABAP 释放 TR 遇到错误消息 ended with return code 8 的含义和处理办法
- Spartacus 4.3.x 版本导入 Cart 到 App Module 构造函数的错误消息
- paip.配置ef_unified_filter() failed ext_filter_module mod_ext_filter.so apache 错误解决
- paip.python错误解决2
- HiveMQ web client客户端运行出错的错误分析
- POST请求 status 415错误解决方法
- 【异常】Dbeaver配置JDBC连接ES时提示SQL错误:current license is non-compliant for [jdbc]
- 【错误记录】Android Studio 编译报错 ( Error: Duplicate resources | 使用 sourceSets 配置多个 res 资源不能有重复名称的资源 )
- 【错误记录】Visual Studio 中配置 NDK 头文件路径 ( NDK 的三个头文件路径 | 与 CPU 架构相关 asm 头文件路径选择 )
- LabVIEW使用VI Server的时候出现1003错误
- windows下建立文件的换行符^M导致linux下的shell脚本执行错误的解决方式
- Centos8 fstab文件配置错误导致机器起不来问题解决
- 服务器配置 iis 上传图片--HTTP 错误 401.3
- Win10 重装系统后,在此计算机上自动解锁此驱动器,提示:数据错误(循环冗余检查)
- 操作系统权限提升(十)之系统错误配置-计划任务提权
- 操作系统权限提升(九)之系统错误配置-泄露敏感信息提权
- android studio Gradle错误The specified Gradle distribution ‘https://services.gradle.org/distributions/