fix(server): 8081 改 TLS 专用、明文入口挪到 8082 —— 同端口不能混用 ssl 标志

上一版想在 8081 上同时用明文块和 ssl 块,nginx 不认:同一个 address:port 的 ssl 标志必须一致,混用直接校验失败,报错还指向那个明文块的行号(容易看错地方)。那份配置因此从未加载成功。

改成:8081 只做 TLS(域名 https://www.dqrcfwpt.com:8081/,HSTS 升级后正好走这里);明文入口挪到 8082(http://117.172.73.106:8082/,给 IP 兜底,HSTS 管不到 IP,所以这条永远可用)。两者共用同一份 snippet。443 仍是生产占位页。
1个文件已修改
38 ■■■■■ 已修改文件
.scratch/server-testenv/nginx-talent-card.conf 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.scratch/server-testenv/nginx-talent-card.conf
@@ -3,18 +3,22 @@
# 部署位置:/etc/nginx/sites-available/talent-card  (软链到 sites-enabled/)
#
# 端口分工:
#   8081 → **测试环境**(完整功能,用 snippets/talent-card-locations.conf)
#         同一个端口同时接受明文与 TLS:
#           http://117.172.73.106:8081/            ← IP 访问(明文;HSTS 管不到 IP,所以它永远可用)
#           https://www.dqrcfwpt.com:8081/          ← 域名访问(必须走 TLS,见下)
#   8081 → **测试环境(TLS 入口)**:https://www.dqrcfwpt.com:8081/
#   8082 → **测试环境(明文兜底)**:http://117.172.73.106:8082/   (用 IP 访问时走它)
#   80   → 只做 301 跳到 https
#   443  → 这个域名留给**生产环境**,目前**尚未部署**,所以只显示占位页
#
# ⚠️ 为什么 8081 必须有 TLS:443 上发了 HSTS(max-age=86400),而 **HSTS 是按“主机”生效的、
#    覆盖该主机的所有端口**(RFC 6797 §8.3:「the HSTS Policy applies to HTTP over any TCP port
#    of an HSTS Host」),且升级时**显式端口会被保留**(`http://host:8081` → `https://host:8081`)。
#    所以只要浏览器收过一次 HSTS,`http://www.dqrcfwpt.com:8081` 就会被强制升级成 https;
#    8081 上没有 TLS 监听时,用户看到的就是“打不开”。加上这个 ssl 块之后才正常。
# ⚠️ 为什么 8081 必须是 TLS、明文入口要另开一个端口:
#   443 上发了 HSTS(max-age=86400),而 **HSTS 按“主机”生效、覆盖该主机的所有端口**
#   (RFC 6797 §8.3:「the HSTS Policy applies to HTTP over any TCP port of an HSTS Host」),
#   且升级时**显式端口会被保留**(`http://host:8081` → `https://host:8081`)。
#   所以浏览器一旦收过 HSTS,`http://www.dqrcfwpt.com:8081` 就会被强制升级成 https ——
#   8081 若只说纯 HTTP,用户看到的就是“打不开”。
#
#   那能不能让 8081 同时说明文和 TLS?**不能让 nginx 用两个 server 块分别 listen**:
#   nginx 要求同一个 address:port 的 ssl 标志一致,混用会直接校验失败
#   (报 `no "ssl_certificate" is defined for the "listen ... ssl" directive`,
#   而且错误会指向那个**明文**块的行号,很容易看错地方)。所以明文入口拆到 8082。
#
# 生产上线时怎么切:把 443 那个 server 块里的 `root` 与两个 location 换成
# `root <生产的 dist 目录>;` + `include snippets/talent-card-locations.conf;`,80 的 301 不用动。
@@ -24,14 +28,7 @@
#       **2027-02-11 到期,且不会自动续到本机** —— 到期前重新下载再传一次。
# HSTS 仍是第一步:max-age=86400,无 includeSubDomains / preload。
# 明文入口:给 IP 访问用,也给任何还没有 HSTS 记录的客户端用
server {
    listen 8081;
    server_name _;
    include snippets/talent-card-locations.conf;
}
# TLS 入口:域名 + 8081。浏览器一旦有了 HSTS 就会走这里
# 测试环境 · TLS 入口(域名)
server {
    listen 8081 ssl;
    http2 on;
@@ -53,6 +50,13 @@
    include snippets/talent-card-locations.conf;
}
# 测试环境 · 明文兜底(IP 访问用;HSTS 管不到 IP,所以这条永远可用)
server {
    listen 8082;
    server_name _;
    include snippets/talent-card-locations.conf;
}
server {
    listen 80;
    server_name www.dqrcfwpt.com dqrcfwpt.com;