When the front-end requests the back-end service, the error 502 bad gateway is constantly reported, and the service on the back-end is started normally. Later, I checked the nginx error log and found that when requesting the backend interface, nginx reported no live upstreams while connecting to upstream. Looking at the explanation of the error, the result is that there is no server in the upstream that can provide services, that is, nginx can no longer find the surviving backend. However, I can use the server directly accessing the backend, which proves that the server side is available.
Finally, I searched the document and found that the problem occurred in the business that required the session to be maintained, but nginx did not maintain the session from the backend. Then, nginx would of course not find the available services on the backend, and would report no live upstream. For detailed explanations of the principles, please refer to the following document.
Reference Documents
Modify nginx configuration
upstream xxxxxxx {
server 172.17.192.98:8087 max_fails=3 fail_timeout=5s weight=1;
server 172.17.192.99:8087 max_fails=3 fail_timeout=5s weight=1;
keepalive 256; //Add keepalive configuration
}
location ^~ /xxxxxx/ {
...
proxy_http_version 1.1;
proxy_set_header Connection ""; //Regularly enforce the use of the 1.1 protocol
...
}