【问题标题】:letsencrypt and nginx 404 errorletencrypt 和 nginx 404 错误
【发布时间】:2017-09-24 00:24:29
【问题描述】:

我正在尝试使用带有 nginx 的数字海洋服务器配置 ssl,但我遇到了问题。 我在同一台服务器上有 4 个网站,其中 3 个运行良好,但最后一个似乎反复无常。 要设置我的证书(使用 ssl 启用 https),我正在关注本教程(使用letsencrypt): https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04

我准确地说,我对 4 个网站使用了相同的证书。 运行此命令时出现问题

sudo letsencrypt certonly -a webroot --webroot-path=/projects/mysite/staging/backend -d staging.backend.mysite.com -d www.staging.backend.mysite.com

它返回给我这个错误:

Failed authorization procedure. staging.backend.mysite.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://staging.backend.mysite.com/.well-known/acme-challenge/jyYxmJYByVQS_HPf7at04LZkirwKe3rOHCeMYcNk1XA: "<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>", www.staging.backend.mysite.com (http-01): urn:acme:error:unauthorized :: The client lacks sufficient authorization :: Invalid response from http://www.staging.backend.mysite.com/.well-known/acme-challenge/-CPeTAThAt2XBMP28LiJmaJxhWDgtU6ysRvgfVv3o5s: "<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>"

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: staging.backend.mysite.com
   Type:   unauthorized
   Detail: Invalid response from http://staging.backend.mysite.com
   /.well-known/acme-
   challenge/jyYxmJYByVQS_HPf7at04LZkirwKe3rOHCeMYcNk1XA: "<html>
   <head><title>404 Not Found</title></head>
   <body bgcolor="white">
   <center><h1>404 Not Found</h1></center>
   <hr><center>"

   Domain: www.staging.backend.mysite.com
   Type:   unauthorized
   Detail: Invalid response from
   http://www.staging.backend.mysite.com/.well-known/acme-
   challenge/-CPeTAThAt2XBMP28LiJmaJxhWDgtU6ysRvgfVv3o5s: "<html>
   <head><title>404 Not Found</title></head>
   <body bgcolor="white">
   <center><h1>404 Not Found</h1></center>
   <hr><center>"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address.

当我尝试使用 Chrome 访问 http://staging.backend.mysite.com/ 时,它会返回此错误:

NET::ERR_CERT_COMMON_NAME_INVALID

这是我的 nginx 配置:

server {
    listen 80;
    listen [::]:80;
    server_name staging.backend.mysite.com www.staging.backend.mysite.com;

    location / {
        proxy_pass http://127.0.0.1:8900/;
    }
}


server {
    listen 8900;
    server_name my.site.ip.adresse;

    location = /favicon.ico {
        access_log off;
        log_not_found off;
    }

    location /static/ {
        root /projects/mysite/staging/backend;
    }

    location /media/ {
        root /projects/mysite/staging/backend;
    }

    location ~ /.well-known {
        allow all;
    }

    location / {
        proxy_pass http://unix:/projects/mysite/staging/backend/run/mysite.sock;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header Host $http_host;
        proxy_redirect off;
    }
}

如您所见,服务器块上没有 ssl 配置,因为教程说稍后再添加。 它适用于其他 3 个站点。我的配置有问题吗?

【问题讨论】:

  • 是因为您没有.well-known 的根文件夹吗?
  • 根据教程无需为知名位置指定根文件夹。
  • 您是否尝试将location ~ /.well-known 复制到实际受到攻击的虚拟服务器上?
  • 当我运行letsencrypt 命令时,会自动创建知名文件夹。
  • 正确的是在 nginx 之外。但是你告诉letsencrypt在端口80上点击staging.backend.mysite.com,nginx转发到端口8900。我曾经读过以'。'开头的位置。默认情况下被 nginx 解雇,但我找不到该参考。所以我建议您将该位置块复制到端口 80 虚拟服务器,看看是否有帮助。

标签: ssl nginx digital-ocean lets-encrypt


【解决方案1】:

我通过禁用 nginx 中的代理并确保 .well-known 在我的 http 根目录中来解决此问题(您的 8900 服务器块中没有根指令,添加一个作为临时。这必须指向文件系统中的一个目录,它是 /projects/mysite/staging/backend/.well-known 基于您提供给letsencrypt命令的webroot路径)。

确保您可以从浏览器访问 sample.com/.well-known,运行 Let's Encrypt 安装,然后重新打开您的代理。

您的 .well-known 块应该不是必需的。也不确定为什么您在 nginx 中同时在 80 和 8900 上提供服务。为什么不直接将 80 代理到您的套接字并跳过在 8900 上的服务?

【讨论】:

    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2017-10-02
    • 2014-03-25
    • 1970-01-01
    • 2015-10-17
    • 2017-02-09
    • 2023-04-03
    • 2017-12-07
    相关资源
    最近更新 更多