今天有同事找我,說圖片上傳以後,不知道去哪裏了。分析了一下問題,找到緣由以後作了處理,這裏簡要記錄一下。html
問題緣由:nginx
1.首前後臺log並沒有錯誤信息;web
2.撿查了一下瀏覽器,發現network中有報錯,413 Request Entity Too Large,但前臺未報錯。centos
解決辦法:api
1.備份Nginx配置文件;(我的習慣,省得修改以後,若是須要還原,忘記原來的配置)瀏覽器
2.查看當前Nginx配置文件:tomcat
[root@VM_0_16_centos nginx]# cat nginx.conf | grep client_max_body_size測試
client_max_body_size 10m;ui
client_max_body_size 10m;this
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
...