我有两个相同的 docker 容器在 CentOS7 服务器的不同端口上运行。旧版本在 81 端口上运行,新版本在 8080 端口上运行(也检查了 82,83)。
当我尝试代理第二个容器并将端口从 81 更改为 8080 时,我收到 nginx 错误消息(HTTP/1.1 502 Bad Gateway)。
Nginx 不在容器中。我只是将它安装在服务器上。
这是我的 proxy_pass 设置:
location / {
proxy_pass http://0.0.0.0:8080/;
}
还有一些附加信息:
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
如果我尝试通过它们的端口直接访问容器,一切正常。
curl 0.0.0.0:81
{"msg":"Phone Masks service"}
curl 0.0.0.0:8080
{"msg":"Phone Masks service"}
nginx版本:nginx/1.16.1
Docker 版本 19.03.4,构建 9013bf583a
完整的服务器配置非常标准,除了 proxy_pass 设置我没有更改任何内容
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://0.0.0.0:8080/;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
我用来启动容器的命令:
sudo docker run --rm -it -p 8080:8080 -e PORT="8080" api
sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
47ef127e3e49 api "/start.sh" 26 minutes ago Up 26 minutes 80/tcp, 0.0.0.0:8080->8080/tcp infallible_borg
5d5fe891ba30 api "/start.sh" 7 hours ago Up 7 hours 80/tcp, 0.0.0.0:81->81/tcp hopeful_cerf