爱鲁迅

建了个新站:爱鲁迅,计划收集鲁迅的全部文章。从功利的角度考虑,读鲁迅的文章,有利于思维能力的锻炼。其文章之所以尖锐、深刻,源于其思维方式是“第一原理”。

这个站探索了SSL的配置,即使用了https安全协议。因为个人博客分享在微信朋友圈中,无法直接打开,没有备案的站点经常这样。https能一定程度改善这个问题。

下面记录SSL的配置过程:

环境:

CentOS:7
Nginx:1.10.0

第一步:申请 Let’s Encrypt 免费证书

1、安装 Certbot

yum install certbot -y

2、执行:

certbot certonly -d "ailuxun.com" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory

根据提示输入:

(1)邮箱,回车
(2)A,回车
(3)Y,回车
(4)Y,回车

看到Press Enter to Continue时暂停,登录域名解析管理,添加一条TXT记录,看终端中的提示信息,name为_acme-challenge,值是下面的一串字符。

继续在终端中回车,等待执行成果。

第二步:配置 Nginx 开启https

1、将 http 跳转至 https:


server {
listen 80;
server_name ailuxun.com www.ailuxun.com;
return 301 https://$server_name$request_uri;
}

2、配置SSL:


server {
listen 443;
server_name ailuxun.com;
root /home/wwwroot/ailuxun.com;
index index.html index.htm;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

}

3、重新加载Nginx:

nginx -s reload

第三步:自动续期证书

crontab -e

15 2 * */2 * certbot renew --quiet --renew-hook "service nginx restart"