【发布时间】:2019-05-29 21:39:32
【问题描述】:
请帮忙。
我找到了一篇博文,https://blog.ssdnodes.com/blog/host-multiple-ssl-websites-docker-nginx/),关于部署多个具有相同 nginx-proxy 但具有不同 VIRTUAL_HOST 名称的 docker-compose 应用程序
但由于某种原因,两个应用程序都返回错误 502 Bad Gateway
以下错误是我在运行docker-compose logs nginx 时看到的
2019/05/29 20:52:26 [error] 8#8: *15 connect() failed (111: Connection refused) while connecting to upstream, client: 52.209.30.187, server: gregsithole.com, request: "GET / HTTP/1.1", upstream: "http://172.20.0.5:80/", host: "gregsithole.com"
而且我相信upstream 使用的是内部 docker 网络 IP,因为这不是我的服务器的 IP。我的上游由以下文件确定:https://raw.githubusercontent.com/jwilder/nginx-proxy/master/nginx.tmpl
但我不太熟悉它的工作原理。
以下是我的 docker-compose 文件的示例:
nginx-proxy/docker-compose.yaml
version: "3.6"
services:
nginx:
image: nginx
container_name: nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
labels:
- "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true"
dockergen:
image: jwilder/docker-gen
container_name: nginx-proxy-gen
restart: always
depends_on:
- nginx
command: -notify-sighup nginx-proxy -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-proxy-le
restart: always
depends_on:
- nginx
- dockergen
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
NGINX_DOCKER_GEN_CONTAINER: nginx-proxy-gen
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
conf:
vhost:
html:
certs:
networks:
default:
external:
name: nginx-proxy
dockerized-ghost/docker-compose.yaml
version: "3.6"
services:
ghost:
image: ghost
restart: always
expose:
- 80
volumes:
- ../../ghost:/var/lib/ghost/content
environment:
NODE_ENV: production
url: https://blog.gregsithole.com
VIRTUAL_HOST: blog.gregsithole.com
LETSENCRYPT_HOST: blog.gregsithole.com
LETSENCRYPT_EMAIL: hidden-email
networks:
default:
external:
name: nginx-proxy
请帮忙
【问题讨论】:
-
您可以发布您的解决方案吗?我需要知道为什么我的回答不适用于这个问题。
-
@filipe,您的解决方案是我需要将网络(我创建的)分配给每个服务,但是正如我们所说的那样,这并没有解决它......我最初以
nginx、docker-gen和letsencrypt-nginx-proxy-companion开始.然后我在验证它是否有效后添加了letsencrypt-nginx-proxy-companion。我已经添加了解决方案,请在下面查看我的答案
标签: docker nginx docker-compose bad-gateway