我很新于Docker和Docker-compose。
我试图在单个服务器上托管多个HTTPS网站。
由于locahost不是有效的主机,因此无法生成SSL证书。
而且我收到了502坏的网关错误。
似乎nginx-proxy无法正确地将流传输到容器中。
这是我的docker-compose:
在网站级别,我有以下docker-compose文件,其中我运行了两个容器,php-fpm(包括我的WordPress文件)和nginx容器。我正在使用这个nginx容器来添加我的自定义nginx配置文件。
这是在nginx-proxy容器中生成的/etc/nginx/conf.d/default.conf文件。
自从我第一次发布帖子以来,我增加了VIRTUAL_PORT = 80,但没有帮助。
我还尝试直接代理PHP容器,但没有成功。
被代理的nginx容器上进行docker检查显示:
我试图在单个服务器上托管多个HTTPS网站。
由于locahost不是有效的主机,因此无法生成SSL证书。
而且我收到了502坏的网关错误。
似乎nginx-proxy无法正确地将流传输到容器中。
这是我的docker-compose:
version: '3'
services:
nginx-proxy:
image: nginx
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
container_name: nginx-proxy
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./vhost.d:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- ./certs:/etc/nginx/certs:ro
nginx-gen:
image: jwilder/docker-gen
command: -notify-sighup nginx -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
container_name: nginx-gen
restart: unless-stopped
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./vhost.d:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- ./certs:/etc/nginx/certs:ro
- /var/run/docker.sock:/tmp/docker.sock:ro
- ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro
nginx-letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: nginx-letsencrypt
restart: unless-stopped
volumes:
- ./conf.d:/etc/nginx/conf.d
- ./vhost.d:/etc/nginx/vhost.d
- ./html:/usr/share/nginx/html
- ./certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
NGINX_DOCKER_GEN_CONTAINER: "nginx-gen"
NGINX_PROXY_CONTAINER: "nginx-proxy"
networks:
webproxy:
external: true
在网站级别,我有以下docker-compose文件,其中我运行了两个容器,php-fpm(包括我的WordPress文件)和nginx容器。我正在使用这个nginx容器来添加我的自定义nginx配置文件。
version: '3.1'
services:
php:
build: ./docker/php/
restart: unless-stopped
volumes:
- wordpress:/var/www/html
nginx:
image: nginx:1-alpine
restart: unless-stopped
expose:
- 80
- 443
volumes:
- wordpress:/var/www/html
- ./docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx/wordpress.conf:/etc/nginx/wordpress.conf
environment:
- LETSENCRYPT_HOST=
- VIRTUAL_HOST=localhost
- VIRTUAL_PORT=80
volumes:
wordpress: {}
networks:
default:
external:
name: webproxy
这是在nginx-proxy容器中生成的/etc/nginx/conf.d/default.conf文件。
# localhost
upstream localhost {
# Cannot connect to network of this container
server 127.0.0.1 down;
}
server {
server_name localhost;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
return 301 https://$host$request_uri;
}
server {
server_name localhost;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:!DSS';
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/localhost.crt;
ssl_certificate_key /etc/nginx/certs/localhost.key;
ssl_dhparam /etc/nginx/certs/localhost.dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/certs/localhost.chain.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
include /etc/nginx/vhost.d/default;
location / {
proxy_pass http://localhost;
}
还有nginx代理的日志
nginx-proxy | localhost 172.22.0.1 - - [10/May/2018:17:52:40 +0000] "GET / HTTP/2.0" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0"
nginx-proxy | 2018/05/10 17:54:47 [error] 7#7: *4 no live upstreams while connecting to upstream, client: 172.22.0.1, server: localhost, request: "GET / HTTP/2.0", upstream: "http://localhost/", host: "localhost"
自从我第一次发布帖子以来,我增加了VIRTUAL_PORT = 80,但没有帮助。
我还尝试直接代理PHP容器,但没有成功。
被代理的nginx容器上进行docker检查显示:
"Config": {
"Hostname": "4859d3794982",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"443/tcp": {},
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"VIRTUAL_PORT=80",
"LETSENCRYPT_HOST=localhost",
"VIRTUAL_HOST=localhost",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.13.1"
],
"Networks": {
"webproxy": {
"IPAMConfig": null,
"Links": null,
"Aliases": [
"nginx",
"4859d3794982"
],
"NetworkID": "6ac6af1b951c780c1334c55862025bd7916643dd13dc02976f2ed176a7ed7619",
"EndpointID": "3e379cd7a020e65f5ea6db8dbafe144d5b6ad5575b183dee64487f7046f0e3a2",
"Gateway": "172.23.0.1",
"IPAddress": "172.23.0.5",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:17:00:05",
"DriverOpts": null
php
的php进程,而不是localhost
。我非常不清楚您试图实现什么 :) - Paul Becotte