[英]Nginx as reverse proxy for docker containers
我正在嘗試讓Nginx將lan內的代理連接反向轉換到幾個Web應用程序,包括Docker容器中的Web應用程序。
兩個webapp均可通過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,但不能訪問儀表板。
奇怪的是,我之前曾做過這項工作,而且我很確定自己沒有更改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正在按預期工作。 我發現將proxy pass更改為example.com時可以正常工作。 必須是儀表板中發生了一些更改,使事情變得混亂。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.