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

23次阅读
没有评论

共计 1297 个字符,预计需要花费 4 分钟才能阅读完成。

真的是太方便了。

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

做一个软连接即可。

正文完
 0
admin
版权声明:本站原创文章,由 admin 于2018-01-10发表,共计1297字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码