Nginx常见错误码解决方案

302错误

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

解决方案:html

//若是是 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)python

403错误

参考(403错误解决)[https://rumenz.com/rumenbiji/nginx-403-forbidden.html]mysql

413错误

413 Request Entity Too Large

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

解决方案:spring

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太长了sql

解决方案:后端

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

499错误

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

问题的核心就是要排查为何服务端处理时间过长浏览器

可能问题:

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

2.mysql慢查询

经过查看监控:

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

2.后台程序访问正常

3.MySQL没有慢查询

502错误

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

504错误

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

相关文章
相关标签/搜索