如何在 jwilder/nginx-proxy 中监听 443 端口

How to listen 443 port in jwilder/nginx-proxy

我正在使用 https://github.com/jwilder/nginx-proxy 进行 nginx-proxy 设置

端口 80 重定向正常。这意味着我可以使用 test.example.com 通过非 SSL 访问我的网站,但是使用 HTTPS 我收到 chrome 错误“此网页不可用” ERR_CONNECTION_CLOSED"

然后我发现nginx-proxy的default.conf好像没有监听443端口:

upstream docker-reverse-proxy.com {
                            ## Can be connected with "test" network
                    # test_nginx_1
                    server 172.19.0.3:443;
}
server {
    server_name docker-reverse-proxy.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    location / {
            proxy_pass https://docker-reverse-proxy.com;
    }
}

以下是我的配置:

1) docker run -d -p 80:80 -p 443:443 -v /private/etc/ssl/certs:/etc/nginx/certs -v /var/run/docker.sock:/tmp/docker.sock:ro --name nginx-proxy --net=test jwilder/nginx-proxy:alpine

2)docker-compose.yml

version: '3'

services:
  php-fpm:
    build: .
    restart: always
    volumes:
      - web:/www
    networks:
      - backend

  nginx:
    image: nginx:alpine
    restart: always
    environment:
      - VIRTUAL_HOST=docker-reverse-proxy.com
      - VIRTUAL_PROTO=https
      - VIRTUAL_PORT=443
    ports:
      - 80
      - 443
    volumes:
      - web:/www:ro
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
      - /private/etc/ssl/certs:/etc/nginx/certs
    networks:
      - frontend
      - backend
    depends_on:
      - php-fpm

volumes:
  web:

networks:
  backend:
  frontend:
    external:
      name: test

最终在nginx服务器环境下添加CERT_NAME解决:

nginx:
  image: nginx:alpine
  restart: always
  environment:
    - VIRTUAL_HOST=docker-reverse-proxy.com
    - VIRTUAL_PROTO=https
    - VIRTUAL_PORT=443
    - CERT_NAME=YOUR_CERT_NAME ## Add this