Django 和 Certbot - 未经授权、无效响应 (HTTPS)

B. *_*kba 5 django https nginx certbot

我正在尝试使用 Nginx 配置 Certbot (Letsencrypt)。

我收到此错误:

 - The following errors were reported by the server:

   Domain: koomancomputing.com
   Type:   unauthorized
   Detail: Invalid response from
   http://koomancomputing.com/.well-known/acme-challenge/xvDuo8MqaKvUhdDMjE3FFbnP1fqbp9R66ah5_uLdaZk
   [2600:3c03::f03c:92ff:fefb:794b]: "<html>\r\n<head><title>404 Not
   Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404
   Not Found</h1></center>\r\n<hr><center>"

   Domain: www.koomancomputing.com
   Type:   unauthorized
   Detail: Invalid response from
   http://www.koomancomputing.com/.well-known/acme-challenge/T8GQaufb9qhKIRAva-_3IPfdu6qsDeN5wQPafS0mKNA
   [2600:3c03::f03c:92ff:fefb:794b]: "<html>\r\n<head><title>404 Not
   Found</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>404
   Not Found</h1></center>\r\n<hr><center>"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
Run Code Online (Sandbox Code Playgroud)

在 /etc/nginx/sites-available/koomancomputing 中:

server {
listen 80;
server_name koomancomputing.com www.koomancomputing.com;

location = /favicon.ico { access_log off; log_not_found off; }
location /staticfiles/ {
    root /home/kwaku/koomancomputing;
}

location /media/ {
    root /home/kwaku/koomancomputing;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;
}
}
Run Code Online (Sandbox Code Playgroud)

我的 DNS A/AAAA 记录:

在此输入图像描述

我不知道该怎么办,所以我搜索并找到了 django-letsencrypt 应用程序,但我不知道如何使用: 在此输入图像描述

Spo*_*ght 7

AAAA您的域具有通过 IPv6 配置到您的服务器的正确记录,并且 certbot 选择该记录来验证您的服务器。

但是,您在 nginx 下配置的服务器块仅侦听您域的 IPv4 上的端口 80。当 certbot 请求 Let's Encrypt 访问您的质询并颁发证书时,nginx 未配置为在 IPv6 上正确响应质询。在这种情况下,它通常会返回其他内容(例如您的情况下的 404,或默认站点)。

您可以通过修改前两行以同时侦听服务器的所有 IPv6 地址来解决此问题:

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

  # other configuration
}
Run Code Online (Sandbox Code Playgroud)

编辑完成后,重新启动nginx并再次运行certbot。


Con*_*oad 3

您的 Nginx 服务器响应 404 错误,因为它没有定义/.well-knowncertbot 验证质询所需的路由。您需要修改 Nginx 配置文件以告诉它如何响应 certbot 的挑战。

Certbot 可以为您更新 Nginx 配置文件。

  • 首先,确保您的配置文件已启用。运行sudo service nginx reload并检查是否存在名为/etc/nginx/sites-enabled/koomancomputing.

  • 然后,运行certbot --nginx -d koomancomputing.com -d www.koomancomputing.com

--nginx标志告诉 certbot 查找具有匹配服务器名称的 Nginx 配置文件,并使用 SSL 信息更新该文件。

  • 还是同样的问题 (2认同)