Compare commits

...
Author SHA1 Message Date
hellcat a1da019299 fix(fuc-xb): support white host Python 3.10 deployment 2026-11-04 15:12:47 +08:00
hellcat 9c21f9767e fix(fuc-xb): rewrite escaped JSON source URLs through test alias 2026-11-04 15:08:40 +08:00
hellcat e951bd2f40 feat(fuc-xb): add isolated tomtojapan staging reverse proxy
Preserve source authentication and strict upstream TLS. Add only a dedicated white-machine vhost; no shared maps or application changes.
2026-11-04 15:05:36 +08:00
3 changed files with 136 additions and 0 deletions

No files matched your search

+9
View File
@@ -0,0 +1,9 @@
# FUC-XB测试反代
用户2026-11-04明确要求用tomtojapan.online,为本次新入口覆盖默认IP加端口的选型;不更改全局规则。
精确入口`fuc-xb-test.tomtojapan.online`,经白色机HTTPS反代到`fuc-xb-test.gemcook.net`。复用已登记的橙云泛域DNS和Origin CA,反代域名不指向业务服务器。独立Nginx文件,不改旧FUC或其他站点的精确/泛映射。保留测试入口密码、安全Cookie和XB令牌权限。
代码按Git提交/推送,白色机稀疏检出到`/var/www/wwwroot/fuc-xb-test-proxy`,以root运行`python3 scripts/fuc-xb-test-proxy/deploy.py`。脚本拒绝覆盖同名配置、保存已有配置摘要、检查Nginx后平滑reload,失败撤回本次新增链接。上游证书严格校验,Host/SNI为源站,URL路径/查询/Authorization/Cookie原样转发;同站Origin/Referer、Cookie域、Location及正文URL按精确域名转换,跨站值保持。
验收和凭据入口见`docs/maintenance/FUC_XB_STAGING.md`。回退仅删除本次配置链接,`nginx -t`后平滑reload;保留源测试站、Git版本和备份,不删数据库或改变其他反代。WebSocket仅配置透传,不把常规HTTP验证说成真实WebSocket验收。
+51
View File
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""Install only this Git checkout's new staging alias on the registered white host."""
import datetime
import hashlib
import json
import os
import pathlib
import subprocess
def sha(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
if os.geteuid() != 0:
raise SystemExit('Run on the registered white server as root')
source = pathlib.Path(__file__).with_name('nginx.conf').resolve()
root = source.parents[2]
if root != pathlib.Path('/var/www/wwwroot/fuc-xb-test-proxy'):
raise RuntimeError('Wrong deployment checkout')
target = pathlib.Path('/etc/nginx/conf.d/fuc-xb-test-proxy.conf')
if target.exists() or target.is_symlink():
raise RuntimeError('Refuse to overwrite an existing mapping')
cert = pathlib.Path('/etc/white-proxy-origin/tomtojapan.online/fullchain.pem')
subprocess.run(['openssl','x509','-in',str(cert),'-noout','-checkend','604800'], check=True, capture_output=True)
subprocess.run(['nginx','-t'], check=True, capture_output=True)
os.umask(0o077)
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d-%H%M%S')
backup = pathlib.Path('/root/codex-backups/fuc-xb-test-proxy') / stamp
backup.mkdir(parents=True, mode=0o700)
before = {str(p):sha(p) for p in pathlib.Path('/etc/nginx/conf.d').glob('*.conf') if p.is_file()}
head = subprocess.check_output(['git','-C',str(root),'rev-parse','HEAD'],text=True).strip()
manifest = {'commit':head, 'existing_configs':before, 'new_target':str(target), 'new_source':str(source), 'source_sha256':sha(source), 'previous_mapping':'absent'}
(backup/'manifest.json').write_text(json.dumps(manifest,indent=2))
target.symlink_to(source)
try:
subprocess.run(['nginx','-t'], check=True, capture_output=True)
subprocess.run(['systemctl','reload','nginx'], check=True, capture_output=True)
if any(not pathlib.Path(p).is_file() or sha(pathlib.Path(p)) != h for p,h in before.items()):
raise RuntimeError('An existing configuration changed during deployment')
except BaseException:
if target.is_symlink() and target.resolve() == source:
target.unlink()
subprocess.run(['nginx','-t'], check=True, capture_output=True)
subprocess.run(['systemctl','reload','nginx'], check=True, capture_output=True)
raise
result = {'installed':True,'commit':head,'target':str(target),'backup':str(backup),'existing_config_hashes_unchanged':True,'dns_or_certificate_changed':False}
(backup/'result.json').write_text(json.dumps(result,indent=2))
print(json.dumps(result))
if __name__ == '__main__':
main()
+76
View File
@@ -0,0 +1,76 @@
# Dedicated FUC-XB staging alias. Never maps tomtojapan.online to the business IP.
map $http_upgrade $fuc_xb_test_proxy_connection {
default upgrade;
'' close;
}
map $http_origin $fuc_xb_test_proxy_origin {
default $http_origin;
https://fuc-xb-test.tomtojapan.online https://fuc-xb-test.gemcook.net;
}
map $http_referer $fuc_xb_test_proxy_referer {
default $http_referer;
"~^https://fuc-xb-test\.tomtojapan\.online(?<fuc_xb_test_refpath>/.*)?$" https://fuc-xb-test.gemcook.net$fuc_xb_test_refpath;
}
server {
listen 80;
listen [::]:80;
server_name fuc-xb-test.tomtojapan.online;
access_log off;
error_log /var/log/nginx/fuc-xb-test-proxy.error.log crit;
location / { return 301 https://fuc-xb-test.tomtojapan.online$request_uri; }
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name fuc-xb-test.tomtojapan.online;
ssl_certificate /etc/white-proxy-origin/tomtojapan.online/fullchain.pem;
ssl_certificate_key /etc/white-proxy-origin/tomtojapan.online/privatekey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
include /etc/nginx/white-proxy-cloudflare-realip.conf;
access_log off;
error_log /var/log/nginx/fuc-xb-test-proxy.error.log crit;
client_max_body_size 20m;
resolver 1.1.1.1 1.0.0.1 valid=300s ipv6=off;
resolver_timeout 5s;
set $fuc_xb_test_upstream fuc-xb-test.gemcook.net;
add_header Cache-Control "private, no-store" always;
add_header X-Robots-Tag "noindex, nofollow, noarchive" always;
location / {
proxy_pass https://$fuc_xb_test_upstream$request_uri;
proxy_ssl_server_name on;
proxy_ssl_name fuc-xb-test.gemcook.net;
proxy_ssl_verify on;
proxy_ssl_verify_depth 4;
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
proxy_http_version 1.1;
proxy_set_header Host fuc-xb-test.gemcook.net;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Origin $fuc_xb_test_proxy_origin;
proxy_set_header Referer $fuc_xb_test_proxy_referer;
proxy_set_header Authorization $http_authorization;
proxy_set_header Cookie $http_cookie;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $fuc_xb_test_proxy_connection;
proxy_set_header Accept-Encoding "";
proxy_connect_timeout 15s;
proxy_read_timeout 120s;
proxy_buffering off;
proxy_cache off;
proxy_no_cache 1;
proxy_cache_bypass 1;
proxy_hide_header Cache-Control;
proxy_redirect https://fuc-xb-test.gemcook.net/ https://fuc-xb-test.tomtojapan.online/;
proxy_redirect http://fuc-xb-test.gemcook.net/ https://fuc-xb-test.tomtojapan.online/;
proxy_cookie_domain fuc-xb-test.gemcook.net fuc-xb-test.tomtojapan.online;
sub_filter_once off;
sub_filter_types text/css application/javascript application/json;
sub_filter 'https://fuc-xb-test.gemcook.net' 'https://fuc-xb-test.tomtojapan.online';
sub_filter 'http://fuc-xb-test.gemcook.net' 'https://fuc-xb-test.tomtojapan.online';
sub_filter '//fuc-xb-test.gemcook.net' '//fuc-xb-test.tomtojapan.online';
# JSON may escape URL slashes; the exact hostname remains unchanged.
sub_filter 'fuc-xb-test.gemcook.net' 'fuc-xb-test.tomtojapan.online';
}
}