douyinWEB/scripts/_nginx_xfwd_host_cn.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

23 lines
954 B
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Ensure nginx also sends X-Forwarded-Host for dy.nomadro.cn."""
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("82.157.112.245", 22, "ubuntu", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
cmd = r"""
CONF=/www/server/panel/vhost/nginx/dy.nomadro.cn.conf
# add X-Forwarded-Host after Host if missing in proxy blocks
if ! sudo grep -q 'X-Forwarded-Host' "$CONF"; then
sudo sed -i 's/proxy_set_header Host \$host;/proxy_set_header Host $host;\n proxy_set_header X-Forwarded-Host $host;/g' "$CONF"
fi
sudo /www/server/nginx/sbin/nginx -t && sudo /www/server/nginx/sbin/nginx -s reload
grep -n 'X-Forwarded-Host\|proxy_set_header Host' "$CONF" | head -20
"""
_, o, e = c.exec_command(cmd, timeout=30)
print((o.read() + e.read()).decode())
c.close()