初始化1

This commit is contained in:
zg
2026-07-16 13:03:11 +08:00
parent 0bdfcbc1c8
commit e6b0f287cc
100 changed files with 12184 additions and 0 deletions

23
scripts/enable_cors.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# 启用 CORS 跨域支持
# 步骤1: 恢复带 CORS headers 的 nginx.conf
cp /etc/nginx/nginx.conf.bak.cors /etc/nginx/nginx.conf
# 步骤2: 给静态资源 location 也加 CORS
# (因为 add_header Cache-Control 会覆盖 http 块继承的 CORS headers
for f in /etc/nginx/conf.d/*.conf; do
if ! grep -q 'Access-Control-Allow-Origin' "$f"; then
sed -i 's/add_header Cache-Control/add_header Access-Control-Allow-Origin * always;\n add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS" always;\n add_header Access-Control-Allow-Headers "Content-Type, Authorization" always;\n add_header Cache-Control/' "$f"
fi
done
# 步骤3: 验证并重载
echo "=== nginx -t ==="
nginx -t && systemctl reload nginx && echo "=== DONE ==="
# 步骤4: 验证 CORS 是否生效
echo ""
echo "=== 验证 CORS ==="
curl -sI -H "Origin: http://test.com" -k https://gw.server.zgitm.com/ 2>&1 | grep -i access-control
curl -sI -H "Origin: http://test.com" -k https://web.gw.zgitm.com/ 2>&1 | grep -i access-control
echo "=== 完成 ==="