zhuyuan-ice-gl-zy001/TRAE-DEV-20260820/outputs-vpn-20260823/deploy-zy-sub-service/nginx-edit.py

17 lines
551 B
Python

#!/usr/bin/env python3
# 在 guanghulab.com 站点插入 /zy-sub/ 反代(幂等)
p = '/etc/nginx/sites-enabled/guanghulab'
s = open(p).read()
if '/zy-sub/' in s:
print('already-present'); raise SystemExit(0)
anchor = ' ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;\n'
block = anchor + '''
location /zy-sub/ {
proxy_pass http://127.0.0.1:3944;
proxy_set_header Host $host;
}
'''
if anchor not in s:
print('anchor-not-found'); raise SystemExit(1)
open(p, 'w').write(s.replace(anchor, block, 1))
print('inserted')