Files
ykxmz/_build/_cmsg_lightsail.txt
T
xmz7891 892d5891ea 搬到 Lightsail 真服务器 + 加 nginx 给 Cloudflare 回源
== 新架构 ==

    用户 --HTTPS--> Cloudflare CDN --HTTP:80--> nginx
                    (yk.xxmxxs.top)              13.54.30.196
                                                     |
                                                     v
                                            127.0.0.1:13245 (中转)

旧架构是"Cloudflare 隧道"(cloudflared 走 7844 到那台 4G 小机器),
那条线路对 7844 是间歇性阻断的(443 通、7844 不通),
隧道每 3~10 分钟掉一次、公网跟着 530 —— 是"网站容易挂"的主因。

新架构**不用隧道**:新机器有公网 IP,Cloudflare 走标准的
反代(回源 80 端口),这是完全不同的东西,没有 7844 问题。

== 为什么要 nginx 这一层 ==

Cloudflare 只能回源到特定端口:
    HTTP:  80 / 8080 / 8880 / 2052 / 2082 / 2086 / 2095
    HTTPS: 443 / 2053 / 2083 / 2087 / 2096 / 8443
中转跑的 13245 不在列表里,所以中间放一层 nginx。

加了 nginx 之后顺便把中转**改成只监听 127.0.0.1** ——
公网只能通过 nginx 进来,少一个暴露面。实测
http://13.54.30.196:13245 现在是连不上的(000),符合预期。

== nginx 配置要点 ==

  /download/   proxy_buffering on + 显式 Cache-Control 604800 immutable
               (文件名带版本号、内容永不改变,放心长缓存;
                 Cloudflare 缓存后第二次下载不回源)
  /v1/         proxy_read_timeout 180s + **proxy_buffering off**
               (长轮询挂 60 秒,nginx 默认 60 秒就断;而且必须关缓冲,
                 否则要等整个响应完才吐给客户端,那就不是长轮询了)
  /            普通反代
  server_tokens off
  client_max_body_size 200m

== 代码修复 ==

relay.py 的 DATA_DIR 默认值原来是写死的 /root/lanremote-relay。
新机器上服务以 admin 普通用户跑(它没理由要 root),而 /root 是 0700,
部署时直接 PermissionError。改成"脚本所在目录下的 data/"。

== 客户端 ==

2.1.3 里已经让手表端支持"没有证书的中转"(裸 IP 走明文 +
usesCleartextTraffic)。等域名和 Cloudflare 接好之后就是全程 HTTPS 了。

== 新增的运维脚本 ==

  _build/lssh.py                     Lightsail 的 SSH 助手(密钥登录)
  _build/deploy_lightsail.py         首次部署中转
  _build/deploy_lightsail_monitor.py 装监测单元 + 预案
  _build/deploy_lightsail_release.py 按版本部署代码和成品
  _build/check_lightsail.py          看状态
  _build/setup_nginx.py              装配 nginx
  relay/rescue-lightsail.sh          紧急预案(针对新架构重写:
                                     没有隧道了,改成重启中转 / 强杀重拉 /
                                     查防火墙 / 重启整机[默认关])
2026-10-08 22:38:57 +08:00

63 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
搬到 Lightsail 真服务器 + 加 nginx 给 Cloudflare 回源
== 新架构 ==
用户 --HTTPS--> Cloudflare CDN --HTTP:80--> nginx
(yk.xxmxxs.top) 13.54.30.196
|
v
127.0.0.1:13245 (中转)
旧架构是"Cloudflare 隧道"(cloudflared 走 7844 到那台 4G 小机器),
那条线路对 7844 是间歇性阻断的(443 通、7844 不通),
隧道每 3~10 分钟掉一次、公网跟着 530 —— 是"网站容易挂"的主因。
新架构**不用隧道**:新机器有公网 IP,Cloudflare 走标准的
反代(回源 80 端口),这是完全不同的东西,没有 7844 问题。
== 为什么要 nginx 这一层 ==
Cloudflare 只能回源到特定端口:
HTTP: 80 / 8080 / 8880 / 2052 / 2082 / 2086 / 2095
HTTPS: 443 / 2053 / 2083 / 2087 / 2096 / 8443
中转跑的 13245 不在列表里,所以中间放一层 nginx。
加了 nginx 之后顺便把中转**改成只监听 127.0.0.1** ——
公网只能通过 nginx 进来,少一个暴露面。实测
http://13.54.30.196:13245 现在是连不上的(000),符合预期。
== nginx 配置要点 ==
/download/ proxy_buffering on + 显式 Cache-Control 604800 immutable
(文件名带版本号、内容永不改变,放心长缓存;
Cloudflare 缓存后第二次下载不回源)
/v1/ proxy_read_timeout 180s + **proxy_buffering off**
(长轮询挂 60 秒,nginx 默认 60 秒就断;而且必须关缓冲,
否则要等整个响应完才吐给客户端,那就不是长轮询了)
/ 普通反代
server_tokens off
client_max_body_size 200m
== 代码修复 ==
relay.py 的 DATA_DIR 默认值原来是写死的 /root/lanremote-relay。
新机器上服务以 admin 普通用户跑(它没理由要 root),而 /root 是 0700,
部署时直接 PermissionError。改成"脚本所在目录下的 data/"。
== 客户端 ==
2.1.3 里已经让手表端支持"没有证书的中转"(裸 IP 走明文 +
usesCleartextTraffic)。等域名和 Cloudflare 接好之后就是全程 HTTPS 了。
== 新增的运维脚本 ==
_build/lssh.py Lightsail 的 SSH 助手(密钥登录)
_build/deploy_lightsail.py 首次部署中转
_build/deploy_lightsail_monitor.py 装监测单元 + 预案
_build/deploy_lightsail_release.py 按版本部署代码和成品
_build/check_lightsail.py 看状态
_build/setup_nginx.py 装配 nginx
relay/rescue-lightsail.sh 紧急预案(针对新架构重写:
没有隧道了,改成重启中转 / 强杀重拉 /
查防火墙 / 重启整机[默认关])