2016-11-08 42 views
0

我试图让Nginx在一个局域网中反向代理连接到几个Web应用程序,包括码头集装箱内的一些应用程序。Nginx作为码头集装箱的反向代理

双方的webapps可达与proxy_pass网址

我使用以下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,而不是仪表板。

奇怪的是,我有这个工作之前,我敢肯定我没有改变任何基本的码头文件。我错过了什么吗?

编辑:(我目前暴露的端口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" 
+0

请分享有关如何设置'nginx'和'dashboard'容器(例如'docker-compose.yml'文件)的信息。 – ronkot

+0

万一它可能会帮助我想做几乎相同的事情:http://stackoverflow.com/questions/32195108/docker-run-apache-on-host-and-container-for-different-websites/32209615# 32209615这不是重复的,但它是相关的我会说。 – AntoineB

+0

感谢球员们,我发现问题实际上并不在nginx中,而是在仪表板中。这很奇怪,因为它习惯于很好地工作。回到调查中! –

回答

0

Nginx的工作按预期。我发现更改代理传递给example.com时,它工作正常。它必须是仪表板中发生变化的一些东西,可能会造成混乱。