Ssl letsencrypt和nginx 404错误

Ssl letsencrypt和nginx 404错误,ssl,nginx,digital-ocean,lets-encrypt,Ssl,Nginx,Digital Ocean,Lets Encrypt,我正试图用我的数字海洋服务器nginx配置ssl,但我遇到了一个问题。 我在同一台服务器上有4个网站,其中3个运行良好,但最后一个似乎反复无常。 要设置我的证书(使用ssl启用https),我将遵循本教程(使用letsencrypt): 我明确表示,我正在为4个网站使用相同的证书。 运行此命令时出现问题 sudo letsencrypt certonly -a webroot --webroot-path=/projects/mysite/staging/backend -d staging.

我正试图用我的数字海洋服务器nginx配置ssl,但我遇到了一个问题。 我在同一台服务器上有4个网站,其中3个运行良好,但最后一个似乎反复无常。 要设置我的证书(使用ssl启用https),我将遵循本教程(使用letsencrypt):

我明确表示,我正在为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.
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个站点上运行良好。我的配置有问题吗?

我通过在nginx中禁用代理并确保。众所周知的是在我的http根目录中(您的8900服务器块中没有root指令,请添加一个作为临时指令。这必须指向文件系统中的一个dir,即/projects/mysite/staging/backend/。根据您为letsencrypt命令提供的webroot路径可知)

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


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

是因为您没有.well-known的根文件夹吗?没有必要根据教程为众所周知的位置指定根文件夹。您尝试过吗正在将
位置~/.well-known
复制到正在命中的实际虚拟服务器?当我运行letsencrypt命令时,会自动创建已知文件夹。请更正,这是在nginx之外。但是您告诉letsencrypt在nginx正在转发到端口8900的端口80上命中staging.backend.mysite.com。我曾经读取过locatio默认情况下,nginx会忽略以“.”开头的ns,但我找不到该引用。因此,我建议您将该位置块复制到端口80虚拟服务器,以查看是否有帮助。