+-
Nginx常见错误码解决方案

302错误

现象:nginx在使用非80端口做反向代理时,浏览器访问发现返回302错误

解决方案:

//如果是 proxy_set_header Host $host;
//那么改成proxy_set_header Host $host:$server_post;
//没有配置则加上proxy_set_header Host $host:$server_post;

//以下为添加位置
location ^/api {

    proxy_set_header Host $host:$server_post; 
    proxy_pass http://127.0.0.1;
}

400错误

nginx400错误是由于request header过大,通常是由于cookie中写入了较长的字符串所引起的。若cookie太大,可能还需要调整large_client_header_buffers(默认4k)

403错误

参考(403错误解决)[https://rumenz.com/rumenbiji/...]

413错误

413 Request Entity Too Large

上传文件过程中容易出现这个问题,传递的某些数据大小超过了nginx的配置

解决方案:

hhtp{
    client_max_body_size 8M;       //改变这个值
    client_body_buffer_size 128k; //缓冲区大小
}

如果后端是php 修改php.ini
post_max_size = 8M  
upload_max_filesize = 6M
重启php服务

如果后端是Springboot

Spring Boot 1.3.x 
multipart.maxFileSize=8M
multipart.maxRequestSize=8M

Spring Boot 1.4.x and 1.5.x
spring.http.multipart.maxFileSize=8M
spring.http.multipart.maxRequestSize=8M


Spring Boot 2.x
spring.servlet.multipart.max-file-size=8M
spring.servlet.multipart.max-request-size=8M

414错误

414 Request-URI Too Large 请求的url太长了

解决方案:

http{
    client_header_buffer_size 512k;
    large_client_header_buffers 4 512k;
}

499错误

这是nginx定义的一个状态码,用于表示这样的错误:服务器返回http头之前,客户端就提前关闭了http连接

问题的核心就是要排查为什么服务端处理时间过长

可能问题:

1.后台python程序处理请求时间过长

2.mysql慢查询

通过查看监控:

1.cpu和内存的使用,都在正常范围

2.后台程序访问正常

3.MySQL没有慢查询

502错误

502 Bad Gateway:作为网关或者代理工作的服务器尝试执行请求时,从上游服务器接收到无效的响应

504错误

504 Gateway Time-out:作为网关或者代理工作的服务器尝试执行请求时,未能及时从上游服务器(URI标识出的服务器,例如HTTP、FTP、LDAP)或者辅助服务器(例如DNS)收到响应。