我试图通过群中的nginx容器将请求反向代理到共享相同覆盖网络的独立容器。
tldr;我收到以下错误:
2018/03/15 19:00:35 [emerg] 1#1: invalid host in upstream "http://nginx" in /etc/nginx/nginx.conf:96
nginx: [emerg] invalid host in upstream "http://nginx" in /etc/nginx/nginx.conf:96
独立容器包含一个具有另一个nginx前端的应用程序:
version: "3"
services:
nginx:
restart: always
container_name: my.nginx
build: ./nginx
networks:
- default
- my-overlay-network
depends_on:
- another-service
... other services
networks:
my-overlay-network:
external: true
我使用docker-compose up -d
启动此应用。
我的swarm包含反向代理:
version: "3"
services:
reverseproxy:
build: ./reverseproxy
image: reverse_proxy
networks:
- my-overlay-network
ports:
- "80:80"
- "443:443"
volumes:
- /etc/letsencrypt:/etc/letsencrypt
deploy:
replicas: 10
restart_policy:
condition: on-failure
networks:
my-overlay-network:
external: true
如果我在没有为独立应用程序指定proxy_pass的情况下启动nginx swarm ,我可以像这样成功ping其他主机:
ping http://nginx/
我可以根据nginx日志确认其他主机收到此请求。
但是,如果我在反向代理中指定docker standalone app:
upstream standalone {
server http://nginx/;
}
和
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
... other stuff ...
location / {
proxy_pass http://standalone/;
}
}
我收到以下错误:
2018/03/15 19:00:35 [emerg] 1#1: invalid host in upstream "http://nginx" in /etc/nginx/nginx.conf:96
nginx: [emerg] invalid host in upstream "http://nginx" in /etc/nginx/nginx.conf:96
答案 0 :(得分:0)
尝试在上游之前添加resolver
:
resolver 127.0.0.11;
upstream standalone {
server http://nginx/;
}
127.0.0.11
是嵌入式泊坞窗口DNS服务器的地址
答案 1 :(得分:0)
问题是upstream
的语法不正确:它需要一个主机和端口,所以它应该是:
upstream standalone {
server nginx;
}