我想在我的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获得以下输出(下面显示的代码段):
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
文件夹 .
我该如何解决这些问题?
1 回答
您的Nginx配置文件没有配置,可以访问/ path / to / www / example /目录web .
这是一个简单的配置,它将使您的网站生效并允许LetsEncyrpt创建有效的证书 . 请记住80端口需要访问 .
相应地更改server_name,或使用/ etc / hosts文件配置本地域 .