fix: 修复 status 站点 80 端口重定向写法,certbot 证书签发成功
This commit is contained in:
@@ -39,6 +39,7 @@
|
|||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- 修正监控工具选型:将误准备的上游 Komari(ghcr.io/komari-monitor/komari)镜像与配置替换为 Komari Lite(ghcr.io/nuomiiiii/komari),服务器上误拉的上游镜像已删除。
|
- 修正监控工具选型:将误准备的上游 Komari(ghcr.io/komari-monitor/komari)镜像与配置替换为 Komari Lite(ghcr.io/nuomiiiii/komari),服务器上误拉的上游镜像已删除。
|
||||||
|
- 修复 status.lzwlab.cn 的 80 端口重定向写法:server 级 return 301 会先于 location 匹配执行,导致 ACME 挑战路径被重定向、证书无法签发;改为 location / 内重定向后 certbot 签发成功(Let's Encrypt ECDSA,有效期至 2026-11-24)。
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,11 @@ server {
|
|||||||
location /.well-known/acme-challenge/ {
|
location /.well-known/acme-challenge/ {
|
||||||
root /var/www/certbot;
|
root /var/www/certbot;
|
||||||
}
|
}
|
||||||
|
# 注意:301 必须放在 location / 内,server 级 return 会在 location 匹配前执行,
|
||||||
|
# 导致 ACME 挑战路径也被重定向(踩坑记录见 setup.md)
|
||||||
|
location / {
|
||||||
return 301 https://$host$request_uri;
|
return 301 https://$host$request_uri;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|||||||
@@ -551,6 +551,7 @@ curl -s -o /dev/null -w "%{http_code} -> %{redirect_url}\n" http://127.0.0.1:257
|
|||||||
- `location /`:HEAD 请求直接返回 204;保留 Upgrade/Connection 头(远程终端、实时数据用 WebSocket);`proxy_buffering off`、`client_max_body_size 50M`。
|
- `location /`:HEAD 请求直接返回 204;保留 Upgrade/Connection 头(远程终端、实时数据用 WebSocket);`proxy_buffering off`、`client_max_body_size 50M`。
|
||||||
- `location ^~ /api/rpc2`:Agent 状态长连接单独配置(补 Origin 头、读写超时 3600s),避免被普通页面策略提前断开。
|
- `location ^~ /api/rpc2`:Agent 状态长连接单独配置(补 Origin 头、读写超时 3600s),避免被普通页面策略提前断开。
|
||||||
- 80 端口只保留 `/.well-known/acme-challenge/`(certbot webroot 验证,root=/var/www/certbot),其余 301 跳 HTTPS。
|
- 80 端口只保留 `/.well-known/acme-challenge/`(certbot webroot 验证,root=/var/www/certbot),其余 301 跳 HTTPS。
|
||||||
|
- ⚠️ 80 端口的 301 必须写在 `location / { return 301 ...; }` 内:server 级 `return` 在 rewrite 阶段(location 匹配之前)就终结请求,会把 ACME 挑战路径也一起 301,导致证书签发/续期失败(详见“附:踩坑记录”第 6 条)。
|
||||||
- 443 证书路径指向 `/etc/letsencrypt/live/status.lzwlab.cn/`(certbot 签发后生效)。
|
- 443 证书路径指向 `/etc/letsencrypt/live/status.lzwlab.cn/`(certbot 签发后生效)。
|
||||||
|
|
||||||
安装顺序(证书未签发前不能启用 443 块,否则 `nginx -t` 报证书文件不存在):
|
安装顺序(证书未签发前不能启用 443 块,否则 `nginx -t` 报证书文件不存在):
|
||||||
@@ -561,7 +562,7 @@ sudo install -m 644 -o root -g root /tmp/status-http.conf /etc/nginx/sites-avail
|
|||||||
sudo ln -sf /etc/nginx/sites-available/status.lzwlab.cn-http /etc/nginx/sites-enabled/status.lzwlab.cn-http
|
sudo ln -sf /etc/nginx/sites-available/status.lzwlab.cn-http /etc/nginx/sites-enabled/status.lzwlab.cn-http
|
||||||
sudo install -m 644 -o root -g root /tmp/lzwlab-status.conf /etc/nginx/sites-available/status.lzwlab.cn
|
sudo install -m 644 -o root -g root /tmp/lzwlab-status.conf /etc/nginx/sites-available/status.lzwlab.cn
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
# 2) 证书签发后(见 11.5 自动收尾脚本):
|
# 2) 证书签发后(见 11.5,脚本或手工执行):
|
||||||
sudo ln -sf /etc/nginx/sites-available/status.lzwlab.cn /etc/nginx/sites-enabled/status.lzwlab.cn
|
sudo ln -sf /etc/nginx/sites-available/status.lzwlab.cn /etc/nginx/sites-enabled/status.lzwlab.cn
|
||||||
sudo rm -f /etc/nginx/sites-enabled/status.lzwlab.cn-http
|
sudo rm -f /etc/nginx/sites-enabled/status.lzwlab.cn-http
|
||||||
sudo nginx -t && sudo systemctl reload nginx
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
@@ -571,22 +572,36 @@ sudo nginx -t && sudo systemctl reload nginx
|
|||||||
|
|
||||||
`status.lzwlab.cn` 在 DNSPod(腾讯云云解析)上没有解析记录(权威 NXDOMAIN),公网入口与证书签发依赖该记录。处理方式:
|
`status.lzwlab.cn` 在 DNSPod(腾讯云云解析)上没有解析记录(权威 NXDOMAIN),公网入口与证书签发依赖该记录。处理方式:
|
||||||
|
|
||||||
1. 在 DNSPod 控制台为 `lzwlab.cn` 添加 A 记录:主机记录 `status`,记录值 `1.15.225.173`。
|
1. 在 DNSPod 控制台为 `lzwlab.cn` 添加 A 记录:主机记录 `status`,记录值 `1.15.225.173`(本次部署时由仓库使用者添加)。
|
||||||
2. 服务器上已放置自动收尾脚本 `/tmp/status-watch.sh`(nohup 后台运行,日志 `/tmp/komari-status-watch.log`):每 45 秒检测一次解析,解析生效后自动执行 certbot(webroot 方式)签发证书 → 启用 443 站点 → 移除临时 HTTP 块 → `nginx -t` + reload → 本机自检。
|
2. 服务器上放了一个自动收尾脚本 `/tmp/status-watch.sh`(nohup 后台运行,日志 `/tmp/komari-status-watch.log`),每 45 秒检测一次解析:DNS 生效后它自动尝试 certbot 签发。首次尝试因 11.4 所述的 301 坑失败(ACME 挑战被 301 到 HTTPS 后 404),修复配置后改为手工签发成功(脚本已完成使命并清理):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 手工执行等价命令(脚本超时/失败时用)
|
|
||||||
sudo certbot certonly --webroot -w /var/www/certbot -d status.lzwlab.cn \
|
sudo certbot certonly --webroot -w /var/www/certbot -d status.lzwlab.cn \
|
||||||
--non-interactive --agree-tos -m admin@lzwlab.cn --keep-until-expiring
|
--non-interactive --agree-tos -m admin@lzwlab.cn --keep-until-expiring
|
||||||
|
# Successfully received certificate(ECDSA,有效期至 2026-11-24)
|
||||||
```
|
```
|
||||||
|
|
||||||
证书续期:certbot webroot 方式会随 systemd 定时器自动续期,80 端口挑战块保留在 `status.lzwlab.cn` 站点的 80 server 块中即可。
|
3. 证书签发后启用 443 站点并移除临时 HTTP 块(脚本会自动做,失败时手工执行):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo ln -sf /etc/nginx/sites-available/status.lzwlab.cn /etc/nginx/sites-enabled/status.lzwlab.cn
|
||||||
|
sudo rm -f /etc/nginx/sites-enabled/status.lzwlab.cn-http
|
||||||
|
sudo nginx -t && sudo systemctl reload nginx
|
||||||
|
```
|
||||||
|
|
||||||
|
证书续期:certbot webroot 方式已注册 systemd 定时器自动续期;80 端口 `/.well-known/acme-challenge/` 位置保留在 `status.lzwlab.cn` 站点的 80 server 块中,续期验证直接可用(已验证该路径返回 404/200 而非 301)。
|
||||||
|
|
||||||
### 11.6 验证结果(公网)
|
### 11.6 验证结果(公网)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s -o /dev/null -w "%{http_code}\n" https://status.lzwlab.cn/ # 307/200(面板,首次为 /install 初始化页)
|
curl -s -o /dev/null -w "%{http_code} -> %{redirect_url} ssl=%{ssl_verify_result}\n" http://status.lzwlab.cn/
|
||||||
|
# 301 -> https://status.lzwlab.cn/(HTTP 强制跳 HTTPS)
|
||||||
|
curl -s -o /dev/null -w "%{http_code} -> %{redirect_url} ssl=%{ssl_verify_result}\n" https://status.lzwlab.cn/
|
||||||
|
# 307 -> https://status.lzwlab.cn/install ssl=0(首次为 /install 初始化页,证书链受信任)
|
||||||
|
curl -sL https://status.lzwlab.cn/ | grep -o '<title>.*</title>' # <title>Komari Lite</title>
|
||||||
curl -s https://lzwlab.cn/ | grep -o '服务器状态' # 服务器状态(首页按钮已生效)
|
curl -s https://lzwlab.cn/ | grep -o '服务器状态' # 服务器状态(首页按钮已生效)
|
||||||
|
echo | openssl s_client -connect status.lzwlab.cn:443 -servername status.lzwlab.cn -alpn h2,http/1.1 2>/dev/null \
|
||||||
|
| grep -E "subject=|issuer=|ALPN" # CN=status.lzwlab.cn / Let's Encrypt / h2
|
||||||
```
|
```
|
||||||
|
|
||||||
### 11.7 首次使用
|
### 11.7 首次使用
|
||||||
@@ -617,3 +632,4 @@ sudo docker pull ghcr.io/nuomiiiii/komari:latest && cd /opt/komari && sudo docke
|
|||||||
`registry-mirrors`(docker.m.daocloud.io)后解决。
|
`registry-mirrors`(docker.m.daocloud.io)后解决。
|
||||||
5. `remote.py` 的 `--timeout` 参数必须放在远程命令之前(`python remote.py --timeout 500 "命令"`);
|
5. `remote.py` 的 `--timeout` 参数必须放在远程命令之前(`python remote.py --timeout 500 "命令"`);
|
||||||
放在命令之后会被 argparse 当作远程命令的一部分传给服务器执行。
|
放在命令之后会被 argparse 当作远程命令的一部分传给服务器执行。
|
||||||
|
6. nginx 中 server 级的 `return` 在 rewrite 阶段(location 匹配之前)执行并直接终结请求:`server { location /.well-known/acme-challenge/ {...} return 301 ...; }` 的挑战路径照样会被 301,导致 certbot 签发失败(LE 跟随 301 到 HTTPS 后得到 404)。必须把重定向写进 `location / { return 301 ...; }` 内,让 location 先参与匹配。
|
||||||
|
|||||||
Reference in New Issue
Block a user