Nginx作为docker容器的反向代理

Nginx作为docker容器的反向代理,nginx,docker,reverse-proxy,Nginx,Docker,Reverse Proxy,我试图让Nginx在局域网内反向代理连接到几个web应用程序,包括docker容器内的应用程序 这两个Web应用程序都可以通过proxy_pass url访问 我正在使用以下dockerfile: # 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\

我试图让Nginx在局域网内反向代理连接到几个web应用程序,包括docker容器内的应用程序

这两个Web应用程序都可以通过proxy_pass url访问

我正在使用以下dockerfile:

# 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,但不能访问仪表板

奇怪的是,我以前做过这个,我很确定我没有改变dockerfile的任何基本内容。我错过什么了吗

编辑:(我目前已在端口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时,效果很好。一定是仪表板中的某些更改导致了混乱。

请分享有关如何设置
nginx
仪表板
容器(例如
docker compose.yml
文件)的信息。如果可能有帮助,我想做几乎相同的事情:它不是重复的,但我想说它是相关的。谢谢各位,我发现问题其实根本不在nginx中,而是在仪表板中。这很奇怪,因为它~以前工作得很好~。回到调查!