[英]Nginx reverse proxy for Docker containers
I have a problem with reverse proxy to my Docker services.我的 Docker 服务的反向代理有问题。 I have a local machine with IP 10.0.0.163 and with Docker stack running on it with nginx and portainer (for this question only they matter).我有一台 IP 为 10.0.0.163 的本地机器,并且在其上运行 Docker 堆栈,并使用 nginx 和 portainer(对于这个问题,只有它们很重要)。
docker-compose.yml: docker-compose.yml:
...
portainer:
image: portainer/portainer
ports:
- "9000:9000"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
- "/mnt/StorageDrive/Portainer:/data"
deploy:
placement:
constraints: [node.role == manager]
networks:
...
- proxy
reverse-proxy:
image: reverseproxy:latest
ports:
- "80:80"
networks:
- proxy
networks:
...
proxy:
nginx.conf: nginx.conf:
worker_processes 1; ## Default: 1
events { worker_connections 1024; }
http {
sendfile on;
server {
listen 80;
allow all;
location / {
proxy_pass http://10.0.0.163:9000;
}
}
}
Dockerfile for reverseproxy image:反向代理镜像的 Dockerfile:
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
When trying to access 10.0.0.163 I get error 502 and logs from reverseproxy show this:当尝试访问 10.0.0.163 时,我收到错误 502 并且来自反向代理的日志显示:
2017/10/09 07:43:02 [error] 5#5: *1 connect() failed (113: Host is unreachable) while connecting to upstream, client: 10.255.0.2, server: , request: "GET / HTTP/1.1", upstream: "http://10.0.0.163:9000/", host: "10.0.0.163"
10.255.0.2 - - [09/Oct/2017:07:43:02 +0000] "GET / HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"
When typing 10.0.0.163:9000/ into browser - everything works fine.在浏览器中输入 10.0.0.163:9000/ 时 - 一切正常。 What is the problem?问题是什么? And how can I make it work with this URL我怎样才能使它与这个 URL 一起工作
10.0.0.163/portainer/... -> 10.0.0.163:9000/...
Try to change nginx configuration尝试更改 nginx 配置
server {
listen 80;
allow all;
location / {
proxy_pass http://portainer:9000/;
resolver 127.0.0.11;
}
}
portainer
is container name defined into your docker-compose.yml
file 127.0.0.11
is embedded docker DNS server portainer
是定义在docker-compose.yml
文件中的容器名称127.0.0.11
是嵌入式docker-compose.yml
DNS 服务器
Also.还。 Alternative way.替代方式。 You can use jwilder/nginx-proxy instead of your reverse-proxy.您可以使用jwilder/nginx-proxy代替反向代理。
The problem same me.问题和我一样。
I resolve below,我在下面解决,
# Docker run command
docker run --name portainer --network devops-net -d -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer
# Nginx
location /portainer/ {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://portainer:9000/;
}
location /portainer/api/websocket/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass http://portainer:9000/api/websocket/;
}
# Notice
Portainer default port 9000
Open brower >> https://domain-name.dev/portainer打开浏览器>> https://domain-name.dev/portiner
Read more: https://portainer.readthedocs.io/en/stable/faq.html阅读更多: https : //portiner.readthedocs.io/en/stable/faq.html
Work for me.为我工作。 ^____^ ^___^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.