Files
vf_react/update-nginx-complete.sh
2025-11-22 09:27:12 +08:00

91 lines
2.8 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
echo "========================================="
echo "完整的 Nginx 配置更新"
echo "========================================="
# 备份当前配置
echo "[1] 备份当前配置..."
sudo cp /etc/nginx/sites-available/valuefrontier /etc/nginx/sites-available/valuefrontier.bak.$(date +%Y%m%d_%H%M%S)
echo ""
echo "[2] 请编辑 Nginx 配置文件:"
echo "sudo nano /etc/nginx/sites-available/valuefrontier"
echo ""
echo "在 HTTPS server 块中(约第 228 行location /chat/ 之前)添加:"
echo ""
cat << 'NGINX_CONFIG'
# ============================================
# AI Chat 应用 (Next.js) - MCP 集成
# ============================================
# AI Chat 主应用
location /ai-chat {
proxy_pass http://127.0.0.1:3000/ai-chat;
proxy_http_version 1.1;
# 保持原始 Host 和协议
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Port 443;
# Cookie 传递 - 重要!
proxy_set_header Cookie $http_cookie;
proxy_pass_request_headers on;
# WebSocket 支持
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 禁用缓冲
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding on;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Next.js 静态资源
location ~ ^/ai-chat/(_next|_vercel|__nextjs) {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
# 静态资源缓存
expires 365d;
add_header Cache-Control "public, immutable";
}
# AI Chat 的 API 调用(如果需要)
location ~ ^/ai-chat/(api|mcp) {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Cookie $http_cookie;
proxy_buffering off;
}
NGINX_CONFIG
echo ""
echo "[3] 保存文件后,测试配置:"
echo "sudo nginx -t"
echo ""
echo "[4] 如果测试通过,重载 Nginx"
echo "sudo nginx -s reload"
echo ""
echo "========================================="
echo "访问地址:"
echo "https://valuefrontier.cn/ai-chat"
echo "========================================="