Score:0

Nginx strange upstream address after app restart

in flag

I have an application running in a container with an exposed port 8082. There is also an nginx configuration, part of which is shown below. In a normal situation, I see upstream: 127.0.0.1:8082 in the access log, which is correct. But when I stop the application container and start it again, I see to: localhost in the logs for about 5-6 seconds, which leads to a 502 error on the site. At this time, the application is already live and running on port 8082. Why does this happen?

server {
    server_name acme.com;

    access_log /var/log/nginx/acme.log upstreamlog;

    location / {
       proxy_pass http://localhost:8082;
       proxy_next_upstream error timeout http_502;
       proxy_set_header Host $host;
       proxy_set_header X-Real-IP $remote_addr;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Upgrade websocket;
       proxy_set_header Connection Upgrade;
    }


    listen 443 ssl; # managed by Certbot
    ... some other Certbot lines ...
}
> sudo nginx -T | grep acme.com
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    server_name acme.com;
Score:1
gu flag

Nowadays, localhost means both the IPv4 127.0.0.1 and the IPv6 ::1. When NGINX forwards traffic to the upstream, it takes the host name you gave which yields both IPv4 and IPv6, while I'm guessing your upstream is IPv4 only.

Score:0
in flag

It seems I managed to solve the problem by replacing proxy_pass http://localhost:8082; with proxy_pass http://127.0.0.1:8082;.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.