【发布时间】: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