文章

把 Uptime Kuma 放到独立子域名

#nginx#uptime-kuma#proxy#ssl

为什么要单独放一个子域名

把 Uptime Kuma 放在独立子域名里,主要是为了把监控面板和博客正文分离。

这样做的结果是更清晰的权限边界、更直观的访问路径,也更方便以后单独配置证书、缓存和访问控制。

运行前提

要使用 https://monitor.nununununu.top/,需要满足三个条件:

  1. monitor.nununununu.topA 记录已经指向当前服务器。
  2. Uptime Kuma 容器正在监听 127.0.0.1:30010.0.0.0:3001
  3. 443 端口由 Nginx 持有。

当前这台机器上的 443 已经被别的 TLS 服务占着,所以如果你要真正使用标准 HTTPS 子域名,就得先迁走那个服务,或者换一台独立公网 IP。

反代配置

可以使用下面这份 Nginx 配置:

server {
  listen 80;
  server_name monitor.nununununu.top;
  return 301 https://$host$request_uri;
}

server {
  listen 443 ssl http2;
  server_name monitor.nununununu.top;

  ssl_certificate /etc/letsencrypt/live/monitor.nununununu.top/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/monitor.nununununu.top/privkey.pem;

  location / {
    proxy_pass http://127.0.0.1:3001;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
  }
}

对应的示例文件已经放在 docs/monitor-subdomain.example.conf

配置步骤

  1. 把示例文件复制到 /etc/nginx/sites-available/monitor.nununununu.top
  2. 创建软链到 sites-enabled
  3. certbotmonitor.nununununu.top 申请证书。
  4. 执行 sudo nginx -t
  5. 执行 sudo systemctl reload nginx

验证方式

先访问主页:

curl -I https://monitor.nununununu.top/

再访问 Uptime Kuma 页面本身,看是否返回登录页或控制台重定向。

如果要确认反代头部是否正确,可以查看响应是否带有 X-Frame-OptionsLocation 和标准的 HTTPS 重定向行为。

常见问题

证书申请失败

通常是 DNS 还没生效,或者 80/443 没有按预期指向这台服务器。

页面可以打开但 WebSocket 异常

通常是 UpgradeConnection 头没有转发完整。

直接访问 :3001 更快

可以这么做,但那不是最终推荐方案。长期维护还是应该回到标准子域名和 HTTPS 入口。