添加让我们使用 docker 在 nginx 上加密

发布于 2025-01-10 02:40:12 字数 2269 浏览 0 评论 0原文

无需创建 ssl 证书,使用 docker 的 django 应用程序和 nginx 工作正常

在尝试使用以下命令安装 Lets 加密证书时,我遇到了这个问题。错过了什么?

docker-compose -f docker-compose-deploy.yml run --rm  certbot certonly --manual --webroot-path /var/www/certbot/ -d example.com

以下问题持续存在

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
  Domain: example.com
  Type:   connection
  Detail: Fetching http://example.com/.well-known/acme-challenge/bkNM7S88bVGypFpUHsnNdasfaRgA3GKqTGX2jciYD4H_I: Connection refused

Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

Some challenges have failed.

Docker-compose 文件如下所示:

  proxy:
    build:
      context: ./proxy
    restart: always
    depends_on:
      - app
    ports:
      - 80:8000
      - 443:443
    volumes:
      - static-data:/vol/static
      - ./certbot/conf/:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
  certbot:
    image: certbot/certbot:latest
    volumes:
      - ./certbot/conf/:/etc/letsencrypt
      - ./certbot/www/:/var/www/certbot

NGINX conf 文件:

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://example.com$request_uri;
    }

    location /static {
        alias /vol/static;
    }
}

server {
    listen 443 ssl;
    server_name example.com;

    location / {
        proxy_pass http://example.com; 
    }

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        uwsgi_pass              ${APP_HOST}:${APP_PORT};
        include                 /etc/nginx/uwsgi_params;
        client_max_body_size    10M;
    }
}

without creating ssl certificate, django app and nginx using docker works fine

While trying to install lets encrypt certificate with the following command, I run into this issue. what is being missed?

docker-compose -f docker-compose-deploy.yml run --rm  certbot certonly --manual --webroot-path /var/www/certbot/ -d example.com

Following problem keeps persisting

Certbot failed to authenticate some domains (authenticator: webroot). The Certificate Authority reported these problems:
  Domain: example.com
  Type:   connection
  Detail: Fetching http://example.com/.well-known/acme-challenge/bkNM7S88bVGypFpUHsnNdasfaRgA3GKqTGX2jciYD4H_I: Connection refused

Hint: The Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.

Some challenges have failed.

Docker-compose file looks like this:

  proxy:
    build:
      context: ./proxy
    restart: always
    depends_on:
      - app
    ports:
      - 80:8000
      - 443:443
    volumes:
      - static-data:/vol/static
      - ./certbot/conf/:/etc/letsencrypt
      - ./certbot/www:/var/www/certbot
  certbot:
    image: certbot/certbot:latest
    volumes:
      - ./certbot/conf/:/etc/letsencrypt
      - ./certbot/www/:/var/www/certbot

NGINX conf file :

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    server_tokens off;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://example.com$request_uri;
    }

    location /static {
        alias /vol/static;
    }
}

server {
    listen 443 ssl;
    server_name example.com;

    location / {
        proxy_pass http://example.com; 
    }

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location / {
        uwsgi_pass              ${APP_HOST}:${APP_PORT};
        include                 /etc/nginx/uwsgi_params;
        client_max_body_size    10M;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦萦几度 2025-01-17 02:40:12

Certbot 在 /var/www/ 中创建质询文件,不再在 /var/www/certbot/ 中。

我已经用这个配置解决了我的问题:

location /.well-known/acme-challenge/ {
    root /var/www;                         # no 'certbot' dir here
}

Docker-compose for Nginx and Certbot 部分(命名卷):

volumes:
  - certbot_challenges:/var/www/.well-known/acme-challenge

Command in Certbot 部分(webroot-path=/var/www):

command: certonly -v --dry-run --webroot --webroot-path=/var/www 
           --preferred-challenges http-01 --email [email protected] 
           --agree-tos --no-eff-email --non-interactive --force-renewal 
           -d example.com -d www.example.com

Certbot creates challenge files at /var/www/ not at /var/www/certbot/ anymore.

I have solved my problem with this config:

location /.well-known/acme-challenge/ {
    root /var/www;                         # no 'certbot' dir here
}

Docker-compose for Nginx and Certbot section (named volume):

volumes:
  - certbot_challenges:/var/www/.well-known/acme-challenge

Command in Certbot section (webroot-path=/var/www):

command: certonly -v --dry-run --webroot --webroot-path=/var/www 
           --preferred-challenges http-01 --email [email protected] 
           --agree-tos --no-eff-email --non-interactive --force-renewal 
           -d example.com -d www.example.com
oО清风挽发oО 2025-01-17 02:40:12

错误消息表明加密服务器无法访问质询。端口 80 可能被您的路由器或一般网络(连接您的 Web 服务器的网络)阻止,无法从互联网访问。

关于你的配置本身,我不能透露太多。我之前没有手动做过。我有一个类似的用例,但我使用图像 nginxproxy/acme-companion (分别是旧版本 jrcs/letsencrypt-nginx-proxy-companion)。它有据可查且易于处理。大部分部分是自动发生的,尤其是 nginx 配置和证书刷新。

The error message indicate lets encrypt server can't access the challenge. Port 80 is maybe blocked by your router or the network in general, where your web server is connected, is not accessible from internet.

About your configuration itself, I can't tell much. I haven't it done before manually. I have a similar use case, but I use the image nginxproxy/acme-companion (respectively the legacy version jrcs/letsencrypt-nginx-proxy-companion). It is well documented and easy to handle. Most of the part is happen automatically, especially the nginx configuration and the cert refreshing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文