我有一个应用程序运行在一个具有暴露端口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;
发布于 2023-05-29 18:08:06
现在,localhost
指的是IPv4 127.0.0.1
和IPv6 ::1
。当NGINX将流量转发到上游时,它会使用您给定的主机名,这将产生IPv4和IPv6,而我猜您的上游仅为IPv4。
发布于 2023-05-29 18:02:50
我似乎通过用proxy_pass http://localhost:8082;
替换proxy_pass http://127.0.0.1:8082;
来解决这个问题。
https://serverfault.com/questions/1132170
复制相似问题