这里 certonly 表示我们只需要生成证书,我们不需要它帮我们改服务器配置。--manual 表示手动配置参数。生成证书需要你证明域名属于你,由于我们是通配符自然不能一个一个页面去放文件验证(默认的验证方法,类似 Google 的页面验证),所以用 --preferred-challenges=dns 设置为验证 DNS 记录。--server=https://acme-v02.api.letsencrypt.org/directory 表示使用第二版的 api 服务器,默认的第一版是不支持通配符证书的签发的。最后 -d *.example.com -d example.com 添加你的域名,需要注意的是只包含 *.example.com 的证书是不能用在 example.com 上的,所以我们把两个都写上,生成的证书就会同时包含两个域名。
1 2 3 4
Saving debuglogto /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Enter email address (used for urgent renewal andsecurity notices) (Enter 'c'to cancel): YOUR EMAIL
这里会让你输入你的邮箱。
1 2 3 4 5 6 7
------------------------------------------------------------------------------- Please readthe Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register withthe ACME server at https://acme-v02.api.letsencrypt.org/directory ------------------------------------------------------------------------------- (A)gree/(C)ancel: A
这里输入 A 表示同意条款。
1 2 3 4 5 6 7
------------------------------------------------------------------------------- Would you be willing to share your email address withthe Electronic Frontier Foundation, a founding partner ofthe Let's Encrypt project andthe non-profit organization that develops Certbot? We'd like to send you email about EFF and our work to encrypt the web, protect its users and defend digital rights. ------------------------------------------------------------------------------- (Y)es/(N)o: N
这里问你要不要把邮箱发给 EFF,我不想发就输入了 N。
1 2 3 4 5 6 7 8 9 10 11 12 13
Obtaining a new certificate Performing the following challenges: dns-01 challenge for alynx.xyz dns-01 challenge for alynx.xyz
------------------------------------------------------------------------------- NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine thatisnot your server, please ensure you're okay withthat.
Are you OK with your IP being logged? ------------------------------------------------------------------------------- (Y)es/(N)o: Y
------------------------------------------------------------------------------- Please deploy a DNS TXT record under the name _acme-challenge.alynx.xyz with the following value:
YX3oQEVGxLolEVtiFDF4JCKe1tqB7B-9pwis8zuQZkc
Before continuing, verify the record is deployed. ------------------------------------------------------------------------------- Press Enter to Continue
这里是第一次验证,先别急着回车,去你的 DNS 服务商那里添加一条到 _acme-challenge 的内容为 YX3oQEVGxLolEVtiFDF4JCKe1tqB7B-9pwis8zuQZkc(你的内容不一定和我的一样)的 TXT 记录,然后用 dig -t txt _acme-challenge.example.com @8.8.8.8,检查是否更新完成,最好多查几次,防止缓存导致失败。有消息说国内的 DNS 是访问不到的,我这里用的 CloudFlare。
------------------------------------------------------------------------------- Please deploy a DNS TXT record under the name _acme-challenge.alynx.xyz with the followingvalue:
lKuF76a3GRy7y3M-FVDJ3kif0FQJJwZQUROc6cgG_lk
Before continuing, verify the recordis deployed. ------------------------------------------------------------------------------- Press Enter to Continue Waiting for verification... Cleaning up challenges
IMPORTANT NOTES: - Congratulations! Your certificate andchain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your keyfile has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expireon2018-09-02.To obtain a newor tweaked versionof this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our workby:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
又是一次验证,把刚才的记录内容改成新的, 按照评论的指正,这里是可以建立两个同名记录的,所以不需要修改两次,这里可以再添加一条同样名字但内容不同的记录,然后多 dig 几次再回车,如果没通过重新运行命令会从记录 IP 那里开始。
# Note: You should disable gzip for SSL traffic. # See: https://bugs.debian.org/773332 # # Read up on ssl_ciphers to ensure a secure configuration. # See: https://bugs.debian.org/765782
root /home/example/example.com/;
# Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; error_page 404404.html; server_name example.com;
location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } }