申请通配符证书
# 下载 Certbot 客户端
$ wget https://dl.eff.org/certbot-auto
# 设为可执行权限
$ chmod a+x certbot-auto
# 移动的bin目录下
mv certbot-auto /usr/bin
部署apache
$ sudo certbot-auto --apache
根据命令行提示进行操作
- 校验证书信息
openssl x509 -in /etc/letsencrypt/live/xhope.top/cert.pem -noout -text
- 证书和密钥保存在下列目录
tree /etc/letsencrypt/live/xhope.top/
修改配置文件
- 查看apache配置文件路径
$ httpd -V
- 编辑
/conf.d/ssl.conf
,使用证书。
LoadModule ssl_module modules/mod_ssl.so
Listen 443
<VirtualHost *:443>
ServerName www.xhope.top
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/xhope.top/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xhope.top/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/xhope.top/chain.pem
</VirtualHost>
- 强制跳转到https,在网站的根目录下创建
.htaccess
文件
$ cd /var/www/html
$ vi .htaccess
编辑.htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
- 检查证书状态
https://www.ssllabs.com/ssltest/analyze.html?d=xhope.top
- 其他工具检查
使用 crontab 让 lets encrypt 自动续期
Let’s Encrypt 证书只有 90 天的有效期,一旦我们忘记了就会失效了。所以建议使用 crontab 进行自动续期,让证书一直有效。
$ crontab -e
在编辑模式下添加
0 3 1 * * /usr/bin/certbot-auto renew 2>>/var/log/cert-renew.log >>/var/log/cert-renew.log
用 crontab -l 命令查看一下是否存在刚才添加的定时命令。如果存在的话,那么每月 1 日的凌晨 3 点就会执行一次所有域名的续期操作。不过有请求次数的限制所以别太频繁了。
$ crontab -l
https://www.vpsss.net/1328.html
参考网站:
- https://www.booleanworld.com/adding-https-website-lets-encrypt/
- https://www.jianshu.com/p/df6d13187578
- https://zhuanlan.zhihu.com/p/26309980
- https://www.hi-linux.com/posts/6968.html
- https://httpd.apache.org/docs/2.4/ssl/ssl_howto.html
- https://linuxhostsupport.com/blog/how-to-install-lets-encrypt-on-centos-7-with-apache/
- https://certbot.eff.org/lets-encrypt/centosrhel7-nginx
- https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-centos-7
- http://yhz61010.iteye.com/blog/2365312
- https://towait.com/blog/secure-apache-with-lets-encrypt-on-centos-7/
- https://stringblog.com/%E9%80%9A%E8%BF%87certbot%E9%85%8D%E7%BD%AElets-encrypt%E7%9A%84ssl%EF%BC%88apache%EF%BC%89/
- https://zhuanlan.zhihu.com/p/35155749