Nginix开启SSL支持HTTPS访问(使用Let's Encrypt免费证书)(3)
ssl_session_cache shared:SSL:50m;
ssl_stapling on;
ssl_stapling_verify on;
# 如果是全站 HTTPS 并且不考虑 HTTP 的话可以为响应头添加要求浏览器使用https重定向的 header
add_header Strict-Transport-Security max-age=15768000;
# 禁止外部站点iframe
add_header X-Frame-Options DENY;
# The rest of your server block
root /path/to/root;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
还可以再增加配置80端口跳转到HTTPS:
location / {
return 301 https://$server_name$request_uri;
}
通过此网址查询你的SSL状态:https://www.ssllabs.com/ssltest/analyze.html?d=域名
Let's Encrypt证书只有90天有效期,过期前需要续期
手动续期:
#./letsencrypt-auto renew --force-renewal
可以通过配置脚本自动更新证书。
#!/bin/sh
# This script renews all the Let's Encrypt certificates with a validity < 30 days
if ! /opt/letsencrypt/letsencrypt-auto renew > /var/log/letsencrypt/renew.log 2>&1 ; then
echo Automated renewal failed:
cat /var/log/letsencrypt/renew.log
exit 1
fi
nginx -t && nginx -s reload
开启定时任务Cron
#crontab -e
编辑任务内容
@daily /path/to/renewCerts.sh
顶(2)
踩(0)
- 最新评论