【发布时间】:2016-07-13 08:49:01
【问题描述】:
我有一个监听 8080 端口的服务。这不是容器。
然后,我使用官方镜像创建了一个 nginx 容器:
docker run --name nginx -d -v /root/nginx/conf:/etc/nginx/conf.d -p 443:443 -p 80:80 nginx
毕竟:
# netstat -tupln | grep 443
tcp6 0 0 :::443 :::* LISTEN 3482/docker-proxy
# netstat -tupln | grep 80
tcp6 0 0 :::80 :::* LISTEN 3489/docker-proxy
tcp6 0 0 :::8080 :::* LISTEN 1009/java
Nginx 配置为:
upstream eighty {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name eighty.domain.com;
location / {
proxy_pass http://eighty;
}
}
我已经检查了我可以使用# curl http://127.0.0.1:8080 连接到此服务器
<html><head><meta http-equiv='refresh'
content='1;url=/login?from=%2F'/><script>window.location.replace('/login?from=%2F');</script></head><body
style='background-color:white; color:white;'>
...
它似乎运行良好,但是,当我尝试使用浏览器访问时,nginx 告诉 bt 502 bad gateway response。
我发现这可能是与非容器化进程的打开和容器之间的可见性有关的问题。我可以容器稳定连接到其他非容器进程打开的端口吗?
编辑
upstream { server 127.0.0.1:8080; }:
2016/07/13 09:06:53 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 62.57.217.25, server: eighty.domain.com, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "eighty.domain.com"
62.57.217.25 - - [13/Jul/2016:09:06:53 +0000] "GET / HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0" "-"
upstream { server 0.0.0.0:8080; }:
62.57.217.25 - - [13/Jul/2016:09:00:30 +0000] "GET / HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0" "-" 2016/07/13 09:00:30 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client:
62.57.217.25, server: eighty.domain.com, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8080/", host: "eighty.domain.com" 2016/07/13 09:00:32 [error] 5#5: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 62.57.217.25, server: eighty.domain.com, request: "GET / HTTP/1.1", upstream: "http://0.0.0.0:8080/", host: "eighty.domain.com"
62.57.217.25 - - [13/Jul/2016:09:00:32 +0000] "GET / HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0" "-"
有什么想法吗?
【问题讨论】:
-
只是快速猜测,会不会是服务器地址的原因?您可以尝试将其从 127.0.0.1 更改为 0.0.0.0 吗?如果不是这种情况,则发生其他一些应用程序失败,检查日志或发布它们,我会尝试看看是怎么回事,还将端口(8080)添加到
http://eightyproxy_pass行。 -
我刚刚在帖子中添加了日志。
-
您是否也尝试过更改
proxy_pass? -
是的,我已将
proxy_pass设置为http://0.0.0.0:8080。同样的问题... -
你是在 linux 还是 windows 上使用 docker?