【发布时间】:2017-03-14 12:16:18
【问题描述】:
我正在尝试在我的 Ubuntu 16.0.4 服务器上使用 certbot and letsencrypt,因此我可以安装邮件服务器。
我正在像这样运行 certbot:
sudo /opt/letsencrypt/certbot-auto certonly --agree-tos --webroot -w /path/to/www/example -d example.com -d www.example.com
我从 certbot 得到以下输出(如下所示的 sn-p):
Domain: www.example.com
Type: unauthorized
Detail: Invalid response from
http://www.example.com/.well-known/acme-challenge/QEZwFgUGOJqqXHcLmTmkr5z83dbH3QlrIUk1S3JI_cg:
"<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.
这是我的目录结构:
root@yourbox:/path/to/www/example$ ls -la
total 12
drwxr-xr-x 3 example root 4096 Nov 1 10:17 .
drwxr-xr-x 5 root webapps 4096 Nov 1 10:13 ..
drwxr-xr-x 2 root root 4096 Nov 1 10:36 .well-known
root@yourbox:/path/to/www/example$
root@yourbox:/path/to/www/example$ cd .well-known/
root@yourbox:/path/to/www/example/.well-known$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Nov 1 10:36 .
drwxr-xr-x 3 example root 4096 Nov 1 10:17 ..
root@yourbox:/path/to/www/example/.well-known$
从上面,我可以看到挑战文件不存在 - (大概?)因为,看起来 certbot 无法写入文件夹。
但是,我首先需要检查 nginx 是否设置正确,以及它是否从以句点开头的文件夹中提供文件。
这是网站的 nginx 配置文件(/etc/nginx/sites-available/example):
server {
# Allow access to the letsencrypt ACME Challenge
location ~ /\.well-known\/acme-challenge {
allow all;
}
}
我手动创建了一个测试文件(sudo touch /path/to/www/example/fake)并赋予它正确的权限:
root@yourbox:/path/to/www/example/.well-known/acme-challenge$ ls -l
total 0
-rw-r--r-- 1 example webapps 0 Nov 1 10:45 fake
然后我尝试从浏览器访问http://www.example.com/.well-known/acme-challenge/fake - 并收到 404 错误。
这意味着我有两个错误:
- Nginx 未正确设置以提供来自
.well-known/acme-challenge文件夹的文件 -
/path/to/www/example文件夹中的文件权限错误,导致certbot无法将其自动生成的文件写入.well-known/acme-challenge文件夹。
我该如何解决这些问题?
【问题讨论】:
-
你需要检查
/etc/hosts文件,确保那里有正确的记录,并设置正确的权限,例如例如,chown -R www-data:www-data /path/to/www你的Nginx和php-FPM/Apache应该在“www-data”用户下工作。
标签: nginx file-permissions ubuntu-16.04 lets-encrypt certbot