The following intermittently occurs when Nginx is used as a local proxy to forward back-end requests to resolve cross-domain problems during local development502 Bad Gateway:

At first, I thought it was the back end interface response error, but the back end check found no problem.

Because the Nginx version in the error message is the same as the version on my machine — Nginx /1.21.3, and I use the Nginx proxy forwarding mode, so I start to check from Nginx.

First, add the Nginx error log

Add an error-log configuration to the Nginx configuration to record the error information as follows:

http { ... error_log /var/logs/nginx-error.log error; . }Copy the code

Sudo Nginx -s reload

See the error

When a request fails, you can view the interface error information in /var/logs/nginx-error.log.

2021/12/24 14:11:00 [error] 34049#0: 110 upstream sent too big header while reading response header from upstream, client: 127.0.0.1, server: WXP. CRM, the request: “POST/login/auth. Rjson HTTP / 1.1”, upstream: “xx. Xx. Xx. XXX: 80 / login/auth….” , host: “wxp.com”, referrer: “wxp.com/”

The error message simply means that the size of the response header received from the server exceeds the limit – the default is 1KB

The solution

Since Nginx is used as the proxy server, the proxy_module needs to be configured accordingly

The main Settings are as follows:

proxy_buffer_size 64k;
proxy_buffers   32 32k;
proxy_busy_buffers_size 128k;
Copy the code

proxy_buffer_size

proxy_buffers

proxy_busy_buffers_size