网络证书的获取与更新-certbot
Contents
使用Let's Encrypt
来自动管理证书的获取和更新,来方便网站的搭建。
软件及Nginx插件安装
sudo emerge -va app-crypt/certbot app-crypt/certbot-nginx
使用
sudo certbot certonly --nginx -d xxx.com
后续的操作根据提示完成即可。
证书存放在/etc/letsencrypt/live/xxx.com/
文件夹中
证书查看
certbot
可以列出你系统中所有管理的证书:
sudo certbot certificates
证书更新
手动更新
证书有效期为90天,可以使用命令行手动更新:
sudo certbot certonly --nginx --force-renew -d xxx.com
自动更新
也可以使用crontab
(cronie
)来进行自动更新:
# /etc/crontab
# Global variables
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 5 crontab
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
* * * */2 * certbot certonly --nginx --force-renew -d xxx.com
Nginx配置
在server部分,新增一个server块,示例如下:
......
# SSL example
server {
listen 443 ssl;
server_name xxx.com;
ssl_certificate /etc/letsencrypt/live/skasis.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/skasis.com/privkey.pem;
access_log /var/log/nginx/localhost.ssl_access_log main;
error_log /var/log/nginx/localhost.ssl_error_log info;
root /var/www/localhost/htdocs;
}
rc-service nginx reload
之后应该就可以了。