上文介绍了可能在freenom 上申请免费域名,对于一些小型站点,为了降低建站成本,可以申请免费的https证书。
本文采用let's Encrypt 免费的https证书,由于let's Encrypt配置比较繁琐,官方提供了自动化客户端工具certbot 用于管理证书。
一. 生成证书
yum install -y certbot
certbot certonly --standalone -d test.ml
证书默认生成目录:/etc/letsencrypt/live/test.ml/
二. nginx配置https
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.ml;
ssl_certificate /data/fullchain.pem;
ssl_certificate_key /data/privkey.pem;
# 调优参数
ssl_protocols TLSv1.2 TLSv1.3;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_session_tickets on;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
}
三. 证书续期
letencrpt 证书有效期为3个月,Let's Encrypt会在到期30天,10天分别发送证书到期邮件提醒。只需要重新生成证书即可
certbot renew