免费 SSL 证书申请与自动续期
HTTPS 现在是必选项:不加密的站点浏览器会标「不安全」,微信里打开还会直接拦截。
面板用户
宝塔里最省事:站点设置 → SSL → Let's Encrypt → 勾选域名 → 申请。申请成功后记得打开「强制 HTTPS」。
面板会自动处理续期,正常情况下不用管。
命令行方式
没装面板的话用 acme.sh,比 certbot 轻量:
curl https://get.acme.sh | sh -s email=you@example.com
source ~/.bashrc
用 webroot 模式签发(不用停 Nginx):
acme.sh --issue -d yourdomain.com -d www.yourdomain.com \
--webroot /www/wwwroot/yourdomain.com/public
安装到指定位置并配置自动 reload:
acme.sh --install-cert -d yourdomain.com \
--key-file /etc/nginx/ssl/yourdomain.key \
--fullchain-file /etc/nginx/ssl/yourdomain.crt \
--reloadcmd "systemctl reload nginx"
:::tip 自动续期是自带的
acme.sh 安装时就往 crontab 里写了每日检查任务,到期前 30 天会自动续并执行你指定的 reloadcmd。用 crontab -l 可以看到那条记录。
:::
Nginx 配置
server {
listen 443 ssl http2;
server_name yourdomain.com;
ssl_certificate /etc/nginx/ssl/yourdomain.crt;
ssl_certificate_key /etc/nginx/ssl/yourdomain.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
root /www/wwwroot/yourdomain.com/public;
# ... 其余配置同 HTTP
}
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
return 301 https://$host$request_uri;
}
切到 HTTPS 之后要改的地方
这一步很容易漏,导致页面上出现「混合内容」警告:
- 后台「系统设置」里的站点网址改成
https:// - 支付渠道后台的回调地址、同步跳转地址全部改成
https:// - 如果用了 CDN,回源协议也要跟着改
改完用浏览器开发者工具的 Console 看一眼有没有 Mixed Content 报错。
评论 0