Ubuntu 使用 Certbot 给 Nginx 添加 SSL 证书

Nginx Let's Encrypt HTTPS About 878 words

关于 Certbot

Certbot不用注册Let's Encrypt账号(它会自动帮你注册),不用手动修改配置服务器配置,一行命令搞定。

安装示例

以我的服务器为例(Ubuntu 14.04)。

首先安装Certbot

sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-nginx 

安装好后,只需运行一行代码。

sudo certbot --nginx

剩下的一切会自动完成。Certbot会自动注册账户,检测Nginx配置文件中的域名,询问为哪些域名生成证书,是否将Http重定向到Https等等,最后自动修改Nginx配置并重启,这时网站已经变成了Https`的了。

另外由于证书只有三个月的有限期,还可以运行以下代码,Certbot会启动一个定时任务,在证书过期时自动更新。

sudo certbot renew --dry-run

如果只想生成证书,比如七牛云加速域名的证书(Nginx配置中并没有此域名)。

只需执行以下代码,Certbot会启动一个临时服务器来完成验证(会占用80端口或443端口,因此需要暂时关闭Web服务器),然后Certbot会把证书以文件的形式保存,包括完整的证书链文件和私钥文件。

证书默认是在/etc/letsencrypt/live路径下。

certbot certonly --cert-name example.com

卸载 certbot

apt-get purge software-properties-common
apt-get purge python-certbot-nginx 

参考地址

https://certbot.eff.org/lets-encrypt/ubuntuxenial-nginx

Views: 2,462 · Posted: 2021-05-10

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh