写在前面
这个博客站点smilejay.cn 以前没有支持HTTPS,因为感觉配置挺麻烦的,还要证书啥的,自己玩玩用http感觉就够了;现在好用的AI工具了,刚才就让codex给我配置好了,大约花费10分钟时间。
现在的URL: https://smilejay.cn/
- 我告诉它去ssh直接登录到我的服务器上去修改,提前ssh key免密登录打通。
- 将http协议的访问走HTTP 301 Moved Permanently 重新定向到了 https 协议。
- codex还很专业的备份了我之前的nginx配置,并且考虑到SSL证书会过期的事实,它自动给我做了crontab定时任务每天2次检查并按需续期。
很不错哦! AI加持下,我的运维能力更专业了~
下面的内容是codex干完活后,给我的输出,我觉得很重要,保存一下。
—— 分割线 ——
已完成 smilejay.cn 的 HTTPS 支持配置,并把 HTTP 改成了 301 跳转 HTTPS。
已完成内容
- 安装 certbot
- 已安装
certbot 1.11.0
- 已安装
- 申请 Let’s Encrypt 免费证书
- 证书路径:
/etc/letsencrypt/live/smilejay.cn/fullchain.pem
/etc/letsencrypt/live/smilejay.cn/privkey.pem
- 证书有效期:
notBefore=Jun 10 12:00:17 2026 GMT
notAfter=Sep 8 12:00:16 2026 GMT
- 修改 Nginx 配置
- 已备份原配置:
/etc/nginx/nginx.conf.bak-20260610-205932
- 已启用:
80 端口:301 跳转到 https://smilejay.cn
443 端口:HTTPS 正常服务
- Nginx 配置校验通过
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
- Nginx 已 reload
- 当前监听:
*:80
*:443
[::]:80
[::]:443
- 外部访问验证通过
HTTP:
http://smilejay.cn
HTTP/1.1 301 Moved Permanently
Location: https://smilejay.cn/
HTTPS:
https://smilejay.cn
HTTP/2 200
- 自动续期已配置
已创建:
/etc/cron.d/certbot-renew-nginx
内容为:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# Renew Lets Encrypt certificates twice daily and reload nginx if renewed.
17 3,15 * * * root certbot renew --quiet --deploy-hook "systemctl reload nginx"
并已执行续期 dry-run,结果成功:
Congratulations, all simulated renewals succeeded:
/etc/letsencrypt/live/smilejay.cn/fullchain.pem (success)
当前最终状态
http://smilejay.cn -> 301 跳转到 https://smilejay.cn/
https://smilejay.cn -> 正常返回 200
证书:Let's Encrypt
自动续期:已配置并 dry-run 成功
配置已经生效。