【问题标题】:How do you manage SSL with nginx and docker-compose你如何使用 nginx 和 docker-compose 管理 SSL
【发布时间】:2022-01-16 10:20:36
【问题描述】:

Nginx 的无数教程和配置不一定适合我的用例,我有点不知所措,所以我仍然感到困惑。我不一定需要答案,但需要指出如何使用我的设置设置 SSL 的正确方向。

我的 docker-compose、frontend(react)、api (python/flask)、postgres 和 nginx 中有 4 个服务。

这是我的 nginx 配置

upstream frontend {
  server frontend:3333;
}

upstream api {
  server api:8000;
}

server {
  listen 80;

  location / {
    proxy_pass http://frontend;
  }
  
  location /api {
    rewrite /api/(.*) /$1 break;
    proxy_pass http://api;
  }
}

我在 docker-compose 中的 nginx 服务

nginx:
        depends_on:
          - api
          - frontend
        restart: unless-stopped
        build: ./nginx
        volumes:
         - ./
        ports:
            - "80:80"
            - "443:443"

还有一个 Dockerfile

FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf

我只需要指出使用此配置启动和运行 SSL 所需步骤的正确方向

【问题讨论】:

    标签: docker nginx ssl https docker-compose


    【解决方案1】:

    您想使用 Certbot 创建(和续订)免费 SSL 证书,相应地更新您的 docker-compose

    nginx:
     image: nginx:latest
     container_name: nginx
     restart: always
     volumes:
       - ./nginx.conf:/etc/nginx/nginx.conf
       - /etc/letsencrypt:/etc/letsencrypt
     ports:
       - 80:80
       - 443:443
     networks:
       - my_network
    

    NGINX 配置也需要修改为监听 443 并配置 SSL

    listen              443 ssl http2;
    server_name         myserver.com;
    ssl_certificate     /etc/letsencrypt/live/myserver.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/myserver.com/privkey.pem;
    ssl_protocols TLSv1.2;
    

    您可以查看 From NGINX to Traefik 以查看 NGINX 配置的详细信息。

    【讨论】:

      猜你喜欢
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-24
      • 2019-07-09
      • 2017-11-19
      • 2021-08-10
      • 1970-01-01
      相关资源
      最近更新 更多