Solutions to common error codes of nginx


302 error

Phenomenon: when nginx uses a non-80 port as the reverse proxy, the browser finds that an error 302 is returned


//If proxy_ set_ header Host $host;
//Then change it to proxy_ set_ header Host $host:$server_ post;
//Add proxy if not configured_ set_ header Host $host:$server_ post;

//The following is where to add
location ^/api {

    proxy_set_header Host $host:$server_post; 

400 error

The nginx400 error is caused by the request header being too large. It is usually caused by writing a long string in the cookie. If the cookie is too large, you may also need to adjust large_ client_ header_ Buffers (default 4K)

403 error

Reference (403 error resolution)[…]

413 error

413 Request Entity Too Large

This problem is easy to occur in the process of uploading files. The size of some data transmitted exceeds the configuration of nginx


    client_ max_ body_ size 8M;       // Change this value
    client_ body_ buffer_ size 128k; // Buffer size

If the backend is PHP, modify php.ini
post_max_size = 8M  
upload_max_filesize = 6M
Restart PHP service

If the backend is springboot

Spring Boot 1.3.x 

Spring Boot 1.4.x and 1.5.x

Spring Boot 2.x

414 error

414 request URI too long URL for too large request


    client_header_buffer_size 512k;
    large_client_header_buffers 4 512k;

499 error

This is a status code defined by nginx, which is used to indicate such an error: before the server returns the HTTP header, the client closes the HTTP connection in advance

The core of the problem is to find out why the server takes too long to process

Possible problems:

1. The background Python program takes too long to process the request

2. MySQL slow query

Monitoring by viewing:

1. The use of CPU and memory is within the normal range

2. Background program access is normal

3. MySQL has no slow query

502 error

502 bad gateway: when a server working as a gateway or proxy tries to execute a request, it receives an invalid response from the upstream server

504 error

504 gateway time out: when a server working as a gateway or proxy tries to execute a request, it fails to receive a response from the upstream server (the server identified by the URI, such as HTTP, FTP, LDAP) or the secondary server (such as DNS) in time.

Solutions to common error codes of nginx