Nginx 配置 SSL
安装 Certbot
Certbot 是用来申请 SSL 证书的。Certbot 的安装方式有几种,具体可以在Certbot 官网上查询。
笔者尝试了通过pip进行安装,直接执行pip install certbot即可安装好 Certbot。
安装完成后,可以使用1
sudo certbot -h
查看安装是否成功。如果报错,也可以尝试使用其它安装方式。
如果你使用了 Nginx 服务器,还可以执行1
yum install certbot-nginx
安装 Certbot 的 Nginx 拓展。
配置 Certbot
执行1
sudo certbot --nginx
即可自动完成配置。不过由于涉及到修改 nginx.conf,建议手动进行配置:1
sudo certbot certonly --webroot -w /path/to/your/webroot -d example.com,www.example.com
将/path/to/your/webroot替换为 nginx 的根目录,example.com替换为你的域名,多个域名用逗号隔开,不支持通配符。
如果一切顺利,会输出以下内容:1
2
3
4
5
6
7
8
9
10IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/example.com/fullchain.pem. Your cert
will expire on 20XX-XX-XX. To obtain a new or tweaked version of
this certificate in the future, simply run certbot again. To
non-interactively renew *all* of your certificates, run "certbot
renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
生成的证书将会存放在/etc/letsencrypt/live/目录下。

