Nginx 作为 docker 个容器的反向代理

Nginx as reverse proxy for docker containers

我正在尝试让 Nginx 将局域网内的代理连接反向到多个 Web 应用程序,包括 docker 容器内的应用程序。

两个网络应用程序都可以通过 proxy_pass url

访问

我正在使用以下 docker 文件:

# Set the base image to Ubuntu
FROM ubuntu

RUN apt-get update
RUN apt-get install -y nginx

RUN rm -v /etc/nginx/nginx.conf
RUN echo "daemon off; \n\
 \n\
worker_processes 1; \n\
events { worker_connections 1024; } \n\
 \n\
http { \n\
 \n\
    server { \n\
        listen 99; \n\
 \n\
        server_name dashboard; \n\
        location / { \n\
            proxy_pass http://dashboard:80; \n\
        } \n\
        location /app1 { \n\
            proxy_pass http://otherhostname:9000/app1; \n\
        } \n\
    } \n\
} \n\

" >> /etc/nginx/nginx.conf
EXPOSE 99
CMD service nginx start

当运行将此作为服务(容器)时,我可以访问 app1,但不能访问仪表板。

奇怪的是我以前有过这个工作,而且我很确定我没有更改 docker 文件的任何基本内容。我错过了什么吗?

编辑:(我目前已经在端口 80 上公开了仪表板,并且正在使用 nginx 在 99 上进行测试)

我 运行 nginx 容器有:

docker service create \
    --replicas 1 \
    --name nginx \
    -p 99:99 \
    nginx_image

仪表板也公开了正确的端口。

docker service create \
    --replicas 1 \
    --name dashboard \
    -p 80:8080 \
    dashboard_image

查看 nginx error.log 我发现:

2016/11/08 08:46:41 [error] 25#25: *42 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.255.0.3, server: dashboard, request: "GET / HTTP/1.1", upstream: "http://dockerhostip:80/", host: "dashboard:99"

Nginx 正在按预期工作。我发现将代理传递更改为 example.com 时效果很好。一定是仪表板中发生了一些变化,把事情搞砸了。