앱을 다시 시작한 후 Nginx 이상한 업스트림 주소

앱을 다시 시작한 후 Nginx 이상한 업스트림 주소

노출된 포트 8082가 있는 컨테이너에서 실행 중인 애플리케이션이 있습니다. 아래에 일부가 표시된 nginx 구성도 있습니다. 정상적인 상황에서는 upstream: 127.0.0.1:8082액세스 로그를 보면 맞는 것 같습니다. 하지만 애플리케이션 컨테이너를 중지하고 다시 시작하면 to: localhost약 5~6초 동안 로그에 표시되며 이로 인해 사이트에 502 오류가 발생합니다. 현재 애플리케이션은 이미 활성화되어 포트 8082에서 실행되고 있습니다. 왜 이런 일이 발생합니까?

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;

답변1

요즘에는 localhostIPv4 127.0.0.1와 IPv6를 모두 의미합니다 ::1. NGINX가 트래픽을 업스트림으로 전달할 때 IPv4와 IPv6를 모두 생성하는 호스트 이름을 사용하지만 업스트림은 IPv4 전용인 것으로 추측됩니다.

답변2

proxy_pass http://localhost:8082;으로 교체하여 문제를 해결한 것 같습니다 proxy_pass http://127.0.0.1:8082;.

관련 정보