- 新增完整 README.md 部署规范:架构、端口规划、BBR 跨境优化、 nginx 源码编译+CONNECT 隧道、sing-box(VLESS+REALITY/SS)、mtg(MTProto)、 本机 IP 自动识别、systemd、启动顺序与验证清单 - nginx/nginx.conf:占位符版,proxy_connect_allow all + 回环保护 - sing-box/config.json:占位符版,VLESS+REALITY + SS - systemd/:nginx/sing-box/mtg 服务文件 - scripts/sync-nginx-local-ips.sh:去除真实域名,占位符版 - fake-site/index.html:伪装页(清除真实品牌域名) - 移除过时:traffic-monitor/、pac/、conf.d 具体站点配置 - 所有敏感值(IP/域名/端口/密钥)均以 <占位符> 表示
53 lines
1.6 KiB
Bash
53 lines
1.6 KiB
Bash
#!/bin/bash
|
||
# sync-nginx-local-ips.sh
|
||
# 自动维护 nginx 本机公网 IP 直连规则(/etc/nginx/local_ip_rules.conf):
|
||
# 出站公网 IP(ipify)+ <节点域名> 的 A 记录 = 本机当前公网 IP 集合。
|
||
# 公网 IP 变更时重写规则文件并 reload nginx(仅变更时 reload)。
|
||
# 由 /etc/cron.d/sync-nginx-local-ips 每 5 分钟调用一次。
|
||
#
|
||
# 部署时把 DOMAIN 改为本节点域名。
|
||
set -u
|
||
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
|
||
RULES=/etc/nginx/local_ip_rules.conf
|
||
DOMAIN=<节点域名>
|
||
|
||
ips=""
|
||
# 出站公网 IP
|
||
out=$(curl -s --max-time 8 https://api.ipify.org 2>/dev/null | tr -dc '0-9.')
|
||
# 域名 A 记录(入站公网 IP)
|
||
dns=$(getent ahostsv4 "$DOMAIN" 2>/dev/null | awk 'NR==1{print $1}')
|
||
|
||
for ip in "$out" "$dns"; do
|
||
case "$ip" in
|
||
''|*[!0-9.]*) continue ;;
|
||
esac
|
||
case "|$ips|" in
|
||
*"|$ip|"*) ;;
|
||
*) ips="${ips}|${ip}" ;;
|
||
esac
|
||
done
|
||
|
||
tmp="$RULES.tmp"
|
||
{
|
||
echo "# nginx 本机公网 IP 直连规则(自动生成,勿手改;由 sync-nginx-local-ips.sh 维护)"
|
||
echo "# 公网 IP 变更后本文件会被重写并 reload nginx"
|
||
IFS='|'
|
||
for ip in $ips; do
|
||
[ -n "$ip" ] && echo "if (\$host = \"$ip\") { rewrite ^(.*)\$ /__local\$1 last; }"
|
||
done
|
||
unset IFS
|
||
} > "$tmp"
|
||
|
||
if ! cmp -s "$RULES" "$tmp"; then
|
||
mv "$tmp" "$RULES"
|
||
if nginx -t >/dev/null 2>&1; then
|
||
systemctl reload nginx
|
||
logger -t sync-nginx-local-ips "nginx local-IP rules updated: [${ips#|}]"
|
||
else
|
||
logger -t sync-nginx-local-ips "nginx -t FAILED, rules NOT applied; keeping previous rules"
|
||
rm -f "$tmp"
|
||
fi
|
||
else
|
||
rm -f "$tmp"
|
||
fi
|