← 返回首页

从零部署一个全站 HTTPS 的个人站

2026-10-22 · 系统 / 网络

记录把一台空的阿里云轻量应用服务器(Ubuntu + nginx)变成一个全站 HTTPS 个人站的完整过程。目标不只是“能访问”,而是证书自动续期、HTTP 强制跳转、状态可观测。

1. 站点配置

nginx 用 conf.d 下的独立配置文件管理站点,一个 server 块绑定域名、指定根目录:

server {
    listen 80;
    listen [::]:80;
    server_name snowheart.top www.snowheart.top;
    root /var/www/snowheart;
    index index.html;
    location / { try_files $uri $uri/ =404; }
}

写完先 nginx -t 校验语法,再 systemctl reload nginx 平滑重载,不断连接。

2. 申请证书与自动续期

用 certbot 的 nginx 插件,一条命令完成申请、部署、配置跳转:

certbot --nginx -d snowheart.top -d www.snowheart.top \
  --non-interactive --agree-tos --redirect

--redirect 会自动加上 HTTP→HTTPS 的 301 跳转。certbot 同时注册了 systemd 定时器 certbot.timer,每天检查、到期前自动续期。用演练验证续期链路真的能跑通:

certbot renew --dry-run

3. 防火墙

轻量应用服务器的防火墙在控制台配置,需要放行 80 和 443。系统层 ufw 若启用也要放行。验证监听:

ss -tlnp | grep -E ':80 |:443'

4. 实际踩到的坑

5. 验证

从外网实际访问 https://snowheart.top 与 https://www.snowheart.top,确认 200、证书受信、跳转生效。这一步同时验证了云防火墙 443 已放行。

下一步:把状态采集接进来(见《用 cron + 静态 JSON 做轻量站点监控》),再往后接 Prometheus + Grafana 做真正的监控告警。