「里程碑」全站HTTPS加密

之前自己瞎写了个加密的聊天网页,其实只要把客户端和服务端的连接加密就可以解决这个问题。为了验证两者的通讯,需要经过可信任的中间人(certificate authority)的协助。如果没有中间人,在网站上放所谓的证书也是可以达到目的,比如说:12306网站需要安装的“根证书”。

正巧在论坛看到介绍Let's Encrypt,可以提供免费的证书颁发服务,就顺手把我的服务器管理的域名全站变成HTTPS链接了(部分外部资源,例如网易的音乐链接还是会被浏览器认为是不安全的HTTP链接)。以下是在运行nginx的centOS-7上操作的过程。

其实相当简单,如果用它的certbot脚本的话。

# install packages
yum -y install epel-release mod_ssl openssl  
yum install python-certbot-nginx

# enable https service 
firewall-cmd --zone=public --add-service=https --permanent  
firewall-cmd --reload

# auto configure let's encrypt
cp /etc/nginx/conf.d/<your-domain>.conf <path-to-backup>  
certbot --nginx # answer questions  
certbot renew --dry-run # check renew certification  

由于证书90天就过期了,加上安全考虑,需要定期更新证书:

# edit /lib/systemd/system/certbot-renew.timer
systemctl enable certbot-renew.timer  
systemctl start certbot-renew.timer