Menu Close

certbot一键安装证书,http改为https

真的是太方便了。

1.打开https://certbot.eff.org/,选择服务器和操作系统。

图1

我的是nginx和centos
选择完后会自动跳转到新页面,告诉你如何去配置https.

2.下载certbot-auto

wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

Install
Since it doesn't seem like your operating system has a packaged version of Certbot, you should use our certbot-auto script to get a copy:
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto

3.执行certbot-auto

#--nginx表示使用nginx服务器
sudo ./path/to/certbot-auto --nginx

运行这个命令,会自动匹配系统的虚拟目录(vhost或conf.d),然后选择哪个域名。
然后是否需要http重定向到https.完成之后会自动修改虚拟目录的配置信息,并且已经重启过nginx。

4.自动续期

证书有效时间是90天。可以使用定时任务自动续期。

crontab-e
#将下面内容加入到定时列表
#这里python最好制定具体路径
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && ./path/to/certbot-auto renew

可能出现的问题:
q1:

Error while running nginx -c /etc/nginx/nginx.conf -t.

nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

a1:
它默认nginx的目录是在/etc/nginx,如果你的nginx没有安装在这里,则会提示这个错误。

./certbot-auto --nginx  --nginx-server-root /usr/local/nginx/

使用--nginx-server-root指定你的nginx《目录》,只需要到目录即可。

如果你是用《lnmp一键安装包》安装的,还会有一个问题。
Error while running nginx -c /usr/local/nginx/nginx.conf -t.

nginx: [emerg] open() "/usr/local/nginx/nginx.conf" failed (2: No such file or directory)

它需要用到一些配置文件,默认安装的话,配置文件在nginx的目录下面,《lnmp一键安装包》的配置文件在nginx/conf下。多了一层。
需要

ln -s /usr/local/nginx/conf /usr/local/nginx

做一个软连接即可。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注