#!/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')