update pay function

This commit is contained in:
2025-11-22 09:51:17 +08:00
parent cddf82ce51
commit feb08dc746
17 changed files with 58 additions and 980 deletions

View File

@@ -1,35 +0,0 @@
#!/bin/bash
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
echo "========================================="
echo "检查并修复环境配置"
echo "========================================="
# 1. 创建正确的 .env.local
echo "创建 .env.local 文件..."
cat > .env.local << 'EOF'
# API 配置 - 重要!必须设置
NEXT_PUBLIC_API_URL=http://49.232.185.254:5001
NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn
# Session 配置
SESSION_COOKIE_NAME=session
PORT=3000
EOF
echo "✓ 环境文件已创建"
echo ""
echo "内容:"
cat .env.local
echo ""
# 2. 检查文件是否存在
if [ -f ".env.local" ]; then
echo "✓ .env.local 文件存在"
else
echo "✗ .env.local 文件不存在"
fi
echo ""
echo "请重启 Next.js 服务器Ctrl+C 然后 npm run dev"

View File

@@ -1,44 +0,0 @@
#!/bin/bash
echo "========================================="
echo "检查 Nginx 配置"
echo "========================================="
# 1. 检查配置文件是否包含 ai-chat 配置
echo "检查 /ai-chat 配置..."
if grep -q "location /ai-chat" /etc/nginx/sites-available/valuefrontier; then
echo "✓ 找到 /ai-chat 配置"
grep -A 10 "location /ai-chat" /etc/nginx/sites-available/valuefrontier
else
echo "✗ 未找到 /ai-chat 配置"
echo ""
echo "请添加以下配置到 /etc/nginx/sites-available/valuefrontier"
echo "(在 location /chat/ 之前添加)"
echo ""
cat << 'EOF'
# AI Chat 应用 (Next.js)
location /ai-chat {
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
proxy_set_header Cookie $http_cookie;
proxy_pass_request_headers on;
proxy_buffering off;
}
EOF
fi
echo ""
echo "测试 Nginx 配置:"
sudo nginx -t
echo ""
echo "如果需要编辑:"
echo "sudo nano /etc/nginx/sites-available/valuefrontier"
echo ""
echo "编辑后重载:"
echo "sudo nginx -s reload"

View File

@@ -1,41 +0,0 @@
#!/bin/bash
echo "修复 basePath 配置..."
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 移除 basePath让它在根路径运行
cat > next.config.js << 'EOF'
/** @type {import('next').NextConfig} */
const nextConfig = {
// 不设置 basePath让 Nginx 处理路径重写
// basePath: '/ai-chat',
reactStrictMode: true,
poweredByHeader: false,
outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk',
async rewrites() {
return [
{
source: '/api/:path*',
destination: 'http://localhost:5001/api/:path*',
},
{
source: '/mcp/:path*',
destination: 'http://localhost:8900/:path*',
},
];
},
images: {
domains: ['valuefrontier.cn', 'localhost', '49.232.185.254'],
},
};
module.exports = nextConfig;
EOF
echo "✓ 已移除 basePath"
echo ""
echo "请重启 Next.js (Ctrl+C 然后 npm run dev)"

View File

@@ -1,70 +0,0 @@
#!/bin/bash
echo "========================================="
echo "修复 CORS 和认证问题"
echo "========================================="
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 1. 修改环境配置 - 重要:通过域名访问,这样 Cookie 才能共享
echo "[1] 更新环境配置..."
cat > .env.local << 'EOF'
# 通过域名访问,避免跨域和 Cookie 问题
NEXT_PUBLIC_API_URL=https://valuefrontier.cn
NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn
SESSION_COOKIE_NAME=session
PORT=3000
EOF
echo "✓ 环境配置已更新"
cat .env.local
# 2. 更新 Next.js 配置
echo ""
echo "[2] 更新 Next.js 配置..."
cat > next.config.js << 'EOF'
/** @type {import('next').NextConfig} */
const nextConfig = {
// 生产环境配置 basePath
basePath: process.env.NODE_ENV === 'production' ? '/ai-chat' : '',
assetPrefix: process.env.NODE_ENV === 'production' ? '/ai-chat' : '',
reactStrictMode: true,
poweredByHeader: false,
outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk',
// API 重写 - 开发环境使用
async rewrites() {
// 生产环境不需要重写,直接通过域名访问
if (process.env.NODE_ENV === 'production') {
return [];
}
return [
{
source: '/api/:path*',
destination: 'http://localhost:5001/api/:path*',
},
{
source: '/mcp/:path*',
destination: 'http://localhost:8900/:path*',
},
];
},
images: {
domains: ['valuefrontier.cn', 'localhost', '49.232.185.254'],
},
};
module.exports = nextConfig;
EOF
echo "✓ Next.js 配置已更新"
echo ""
echo "========================================="
echo "请重启 Next.js"
echo "1. 按 Ctrl+C 停止当前服务"
echo "2. 运行: npm run dev"
echo "========================================="

View File

@@ -1,58 +0,0 @@
#!/bin/bash
echo "修复 Next.js 配置..."
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 1. 删除 TypeScript 配置(如果存在)
if [ -f "next.config.ts" ]; then
rm next.config.ts
echo "✓ 删除了 next.config.ts"
fi
# 2. 创建 JavaScript 配置
cat > next.config.js << 'EOF'
/** @type {import('next').NextConfig} */
const nextConfig = {
// 开发环境先不设置 basePath方便测试
// 生产环境再启用basePath: '/ai-chat',
reactStrictMode: true,
poweredByHeader: false,
// 解决多个 lockfile 警告
outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk',
// 重写规则
async rewrites() {
return [
{
source: '/api/:path*',
destination: 'http://localhost:5001/api/:path*',
},
{
source: '/mcp/:path*',
destination: 'http://localhost:8900/:path*',
},
];
},
images: {
domains: ['valuefrontier.cn', 'localhost'],
},
};
module.exports = nextConfig;
EOF
echo "✓ 创建了 next.config.js"
# 3. 重启开发服务器
echo ""
echo "请运行以下命令重启服务器:"
echo "npm run dev"
echo ""
echo "然后访问:"
echo "http://localhost:3000"
echo "或"
echo "http://49.232.185.254:3000"

View File

@@ -1,55 +0,0 @@
# Nginx 配置片段 - 添加到 valuefrontier.conf 的 HTTPS server 块中
# 将这些配置添加到 443 端口的 server 块中,在其他 location 配置之前
# ============================================
# AI Chat 应用 (Next.js)
# ============================================
# AgentChat 应用代理 - 使用新路径避免与现有 /chat/ 冲突
location /ai-chat {
# 重写路径,去掉 /ai-chat 前缀
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
# 保持 Cookie 传递重要Session 共享)
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;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Next.js 静态资源
location ~ ^/ai-chat/(_next|__nextjs) {
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
# 静态资源缓存
expires 1y;
add_header Cache-Control "public, immutable";
}
# MCP API 已经配置在 /mcp/ 路径 (保持不变)
# location /mcp/ { ... } # 已存在,无需修改

40
nginx-correct-config.txt Normal file
View File

@@ -0,0 +1,40 @@
# 正确的 Nginx 配置 - 添加到 valuefrontier.conf 的 HTTPS server 块中
# 在 location /chat/ 之前添加
# ============================================
# AI Chat 应用 (Next.js) - MCP 集成
# ============================================
# 处理 /ai-chat -> /ai-chat/ 重定向
location = /ai-chat {
return 301 /ai-chat/;
}
# 主应用代理
location /ai-chat/ {
# 关键proxy_pass 结尾的 / 会去掉 /ai-chat/ 前缀
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 $scheme;
# 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;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}

View File

@@ -1,79 +0,0 @@
#!/bin/bash
# Nginx 配置更新脚本
# 在 HTTPS server 块中添加 AgentChat 代理配置
echo "========================================="
echo "Nginx 配置更新 - 添加 AgentChat 代理"
echo "========================================="
# 备份原配置
echo "1. 备份原配置文件..."
sudo cp /etc/nginx/sites-available/valuefrontier /etc/nginx/sites-available/valuefrontier.backup.$(date +%Y%m%d_%H%M%S)
echo "2. 添加 AgentChat 配置..."
echo ""
echo "请在 valuefrontier.conf 的 HTTPS server 块中(大约第 228 行chat/ 配置之前)添加以下内容:"
echo ""
cat << 'EOF'
# ============================================
# AI Chat 应用 (Next.js) - MCP 集成
# ============================================
# AgentChat 应用代理
location /ai-chat {
# 重写路径,去掉 /ai-chat 前缀
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
# 保持 Cookie 传递重要Session 共享)
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;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Next.js 静态资源
location ~ ^/ai-chat/(_next|__nextjs) {
rewrite ^/ai-chat(.*)$ $1 break;
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
# 静态资源缓存
expires 1y;
add_header Cache-Control "public, immutable";
}
EOF
echo ""
echo "3. 编辑配置文件:"
echo " sudo nano /etc/nginx/sites-available/valuefrontier"
echo ""
echo "4. 在第 227 行location /chat/ { 之前)插入上述配置"
echo ""
echo "5. 保存并测试配置:"
echo " sudo nginx -t"
echo ""
echo "6. 如果测试通过,重载 Nginx"
echo " sudo nginx -s reload"
echo ""
echo "========================================="

View File

@@ -1,85 +0,0 @@
#!/bin/bash
echo "========================================="
echo "快速修复 AgentChat 配置"
echo "========================================="
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 1. 停止当前进程
echo "停止现有进程..."
pkill -f "next dev" 2>/dev/null
# 2. 创建环境文件
echo "创建环境配置..."
cat > .env.local << 'EOF'
NEXT_PUBLIC_API_URL=http://49.232.185.254:5001
NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn
SESSION_COOKIE_NAME=session
PORT=3000
EOF
# 3. 修复 Next.js 配置
echo "修复 Next.js 配置..."
cat > next.config.js << 'EOF'
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
poweredByHeader: false,
outputFileTracingRoot: '/home/ubuntu/vf_react/src/views/AgentChat/neuratalk',
// 允许跨域开发
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Access-Control-Allow-Credentials',
value: 'true',
},
{
key: 'Access-Control-Allow-Origin',
value: '*',
},
],
},
];
},
// API 代理
async rewrites() {
return [
{
source: '/api/:path*',
destination: 'http://localhost:5001/api/:path*',
},
{
source: '/mcp/:path*',
destination: 'http://localhost:8900/:path*',
},
];
},
images: {
domains: ['valuefrontier.cn', 'localhost', '49.232.185.254'],
},
};
module.exports = nextConfig;
EOF
# 4. 删除 TypeScript 配置(如果存在)
rm -f next.config.ts
echo ""
echo "✓ 配置修复完成"
echo ""
echo "现在请运行:"
echo "npm run dev"
echo ""
echo "然后访问:"
echo "- 直接访问: http://49.232.185.254:3000"
echo "- 通过 Nginx: https://valuefrontier.cn/ai-chat"
echo ""
echo "========================================="

View File

@@ -1,144 +0,0 @@
#!/bin/bash
echo "========================================="
echo "简单解决方案 - 跳过认证检查"
echo "========================================="
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 临时方案:先跳过认证,直接测试功能
cat > components/Chat/MCPChatSimple.tsx << 'EOF'
'use client';
import React, { useState, useRef, useEffect } from 'react';
import { mcpService } from '../../services/mcp-real';
export default function MCPChatSimple() {
const [messages, setMessages] = useState([]);
const [input, setInput] = useState('');
const [isLoading, setIsLoading] = useState(false);
const handleSend = async () => {
if (!input.trim() || isLoading) return;
const userMessage = {
id: Date.now().toString(),
role: 'user',
content: input,
timestamp: new Date(),
};
setMessages(prev => [...prev, userMessage]);
setInput('');
setIsLoading(true);
try {
// 直接调用 MCP
const response = await fetch('/mcp/chat', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
messages: [{ role: 'user', content: input }],
stream: false,
}),
});
const data = await response.json();
setMessages(prev => [
...prev,
{
id: (Date.now() + 1).toString(),
role: 'assistant',
content: data.response || data.message || '没有回复',
timestamp: new Date(),
},
]);
} catch (error) {
console.error('Error:', error);
setMessages(prev => [
...prev,
{
id: Date.now().toString(),
role: 'system',
content: '错误: ' + error.message,
timestamp: new Date(),
},
]);
} finally {
setIsLoading(false);
}
};
return (
<div className="flex h-screen bg-gray-50">
<div className="flex-1 flex flex-col">
<div className="flex-1 overflow-y-auto p-4 space-y-4">
<h2 className="text-2xl font-bold">AI Chat (测试模式 - 无认证)</h2>
{messages.map(msg => (
<div
key={msg.id}
className={\`flex \${msg.role === 'user' ? 'justify-end' : 'justify-start'}\`}
>
<div
className={\`max-w-2xl px-4 py-2 rounded-lg \${
msg.role === 'user'
? 'bg-blue-600 text-white'
: 'bg-white text-gray-900'
}\`}
>
<div className="whitespace-pre-wrap">{msg.content}</div>
</div>
</div>
))}
</div>
<div className="border-t p-4">
<div className="flex space-x-2">
<input
type="text"
value={input}
onChange={e => setInput(e.target.value)}
onKeyPress={e => e.key === 'Enter' && handleSend()}
disabled={isLoading}
placeholder="输入消息..."
className="flex-1 px-4 py-2 border rounded-lg"
/>
<button
onClick={handleSend}
disabled={!input.trim() || isLoading}
className="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:opacity-50"
>
{isLoading ? '发送中...' : '发送'}
</button>
</div>
</div>
</div>
</div>
);
}
EOF
# 修改 page.tsx 使用简单版本
cat > app/page.tsx << 'EOF'
// 临时使用简单版本,跳过认证
import MCPChatSimple from "@/components/Chat/MCPChatSimple";
export default function Page() {
return (
<main className="h-screen">
<MCPChatSimple />
</main>
);
}
EOF
echo "✓ 创建了简单版本(无认证)"
echo ""
echo "重启 Next.js 后访问:"
echo "- http://49.232.185.254:3000"
echo "- https://valuefrontier.cn/ai-chat"
echo ""
echo "这个版本跳过认证,直接测试 MCP 功能"

View File

@@ -1,8 +1,8 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
// 开发环境先不设置 basePath,方便测试 // 设置 basePath 和 assetPrefix 以支持子路径部署
// basePath: '/ai-chat', basePath: '/ai-chat',
// assetPrefix: '/ai-chat/', assetPrefix: '/ai-chat',
// 启用严格模式 // 启用严格模式
reactStrictMode: true, reactStrictMode: true,

View File

@@ -1,122 +0,0 @@
#!/bin/bash
# 一键启动所有服务
echo "========================================="
echo "启动 ValueFrontier 全栈服务"
echo "========================================="
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 1. 检查 MCP 服务器
echo -e "${YELLOW}[1/4] 检查 MCP 服务器 (端口 8900)...${NC}"
if lsof -Pi :8900 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ MCP 服务器已运行${NC}"
else
echo -e "${YELLOW}启动 MCP 服务器...${NC}"
cd /home/ubuntu/vf_react
python3 mcp_server.py > mcp_server.log 2>&1 &
sleep 3
if lsof -Pi :8900 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ MCP 服务器启动成功${NC}"
else
echo -e "${RED}✗ MCP 服务器启动失败,请检查日志${NC}"
fi
fi
# 2. 检查 Flask 主应用
echo -e "${YELLOW}[2/4] 检查 Flask 主应用 (端口 5001)...${NC}"
if lsof -Pi :5001 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ Flask 应用已运行${NC}"
else
echo -e "${YELLOW}启动 Flask 应用...${NC}"
cd /home/ubuntu/vf_react
python3 app.py > flask_app.log 2>&1 &
sleep 5
if lsof -Pi :5001 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ Flask 应用启动成功${NC}"
else
echo -e "${RED}✗ Flask 应用启动失败,请检查日志${NC}"
fi
fi
# 3. 检查 Next.js AgentChat
echo -e "${YELLOW}[3/4] 检查 AgentChat (端口 3000)...${NC}"
if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ AgentChat 已运行${NC}"
else
echo -e "${YELLOW}启动 AgentChat...${NC}"
cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk
# 检查是否已安装依赖
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}安装依赖...${NC}"
npm install
fi
# 检查环境配置
if [ ! -f ".env.local" ]; then
echo -e "${YELLOW}创建环境配置...${NC}"
cat > .env.local << EOL
NEXT_PUBLIC_API_URL=http://localhost:5001
NEXT_PUBLIC_MAIN_APP_URL=https://valuefrontier.cn
SESSION_COOKIE_NAME=session
PORT=3000
MCP_SERVER_URL=http://localhost:8900
EOL
fi
# 启动 Next.js
npm run dev > agentchat.log 2>&1 &
sleep 5
if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null ; then
echo -e "${GREEN}✓ AgentChat 启动成功${NC}"
else
echo -e "${RED}✗ AgentChat 启动失败,请检查日志${NC}"
fi
fi
# 4. 验证服务
echo -e "${YELLOW}[4/4] 验证服务状态...${NC}"
echo ""
echo "服务状态检查:"
echo "----------------------------------------"
# MCP 工具列表
echo -n "MCP 工具接口: "
if curl -s http://localhost:8900/tools > /dev/null 2>&1; then
echo -e "${GREEN}✓ 正常${NC}"
else
echo -e "${RED}✗ 异常${NC}"
fi
# Flask Session
echo -n "Flask 认证接口: "
if curl -s http://localhost:5001/api/auth/session > /dev/null 2>&1; then
echo -e "${GREEN}✓ 正常${NC}"
else
echo -e "${RED}✗ 异常${NC}"
fi
# Next.js
echo -n "AgentChat 应用: "
if curl -s http://localhost:3000/ai-chat > /dev/null 2>&1; then
echo -e "${GREEN}✓ 正常${NC}"
else
echo -e "${RED}✗ 异常${NC}"
fi
echo ""
echo "========================================="
echo -e "${GREEN}访问地址:${NC}"
echo "- 本地测试: http://localhost:3000/ai-chat"
echo "- 生产环境: https://valuefrontier.cn/ai-chat"
echo ""
echo -e "${YELLOW}查看日志:${NC}"
echo "- MCP: tail -f mcp_server.log"
echo "- Flask: tail -f flask_app.log"
echo "- AgentChat: tail -f src/views/AgentChat/neuratalk/agentchat.log"
echo "========================================="

View File

@@ -1,22 +0,0 @@
@echo off
echo Starting AgentChat Next.js Application...
echo =========================================
cd src\views\AgentChat\neuratalk
REM 检查是否已安装依赖
if not exist node_modules (
echo Installing dependencies...
npm install
)
REM 检查是否有 .env.local
if not exist .env.local (
echo Creating .env.local from .env.example...
copy .env.example .env.local
echo Please edit .env.local with your configuration
pause
)
echo Starting development server on http://localhost:3000
npm run dev

View File

@@ -1,23 +0,0 @@
#!/bin/bash
echo "Starting AgentChat Next.js Application..."
echo "========================================="
cd src/views/AgentChat/neuratalk
# 检查是否已安装依赖
if [ ! -d "node_modules" ]; then
echo "Installing dependencies..."
npm install
fi
# 检查是否有 .env.local
if [ ! -f ".env.local" ]; then
echo "Creating .env.local from .env.example..."
cp .env.example .env.local
echo "Please edit .env.local with your configuration"
read -p "Press enter to continue..."
fi
echo "Starting development server on http://localhost:3000"
npm run dev

View File

@@ -1,91 +0,0 @@
#!/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 "========================================="

View File

@@ -158,50 +158,6 @@ server {
proxy_send_timeout 60s; proxy_send_timeout 60s;
proxy_read_timeout 60s; proxy_read_timeout 60s;
} }
location /ai-chat {
# 重写路径,去掉 /ai-chat 前缀
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
# 保持 Cookie 传递重要Session 共享)
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;
# 超时设置
proxy_connect_timeout 60s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Next.js 静态资源
location ~ ^/ai-chat/(_next|__nextjs) {
rewrite ^/ai-chat(.*)$ $1 break;
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 $scheme;
# 静态资源缓存
expires 1y;
add_header Cache-Control "public, immutable";
}
# Elasticsearch API代理价值论坛 # Elasticsearch API代理价值论坛
location /es-api/ { location /es-api/ {
proxy_pass http://222.128.1.157:19200/; proxy_pass http://222.128.1.157:19200/;
@@ -267,7 +223,21 @@ server {
proxy_send_timeout 86400s; proxy_send_timeout 86400s;
proxy_read_timeout 86400s; proxy_read_timeout 86400s;
} }
# AI Chat 应用 (Next.js) - MCP 集成
location /ai-chat {
proxy_pass http://127.0.0.1:3000/ai-chat;
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 $scheme;
proxy_set_header Cookie $http_cookie;
proxy_pass_request_headers on;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_buffering off;
proxy_cache off;
}
# iframe 内部资源代理Bytedesk 聊天窗口的 CSS/JS # iframe 内部资源代理Bytedesk 聊天窗口的 CSS/JS
location /chat/ { location /chat/ {
proxy_pass http://43.143.189.195/chat/; proxy_pass http://43.143.189.195/chat/;

View File

@@ -1,63 +0,0 @@
#!/bin/bash
echo "========================================="
echo "验证 Nginx 配置"
echo "========================================="
# 1. 检查 ai-chat 配置
echo "[1] 检查 Nginx 配置..."
if grep -q "location /ai-chat" /etc/nginx/sites-available/valuefrontier; then
echo "✓ 找到 /ai-chat 配置"
else
echo "✗ 未找到 /ai-chat 配置 - 请添加配置"
exit 1
fi
# 2. 检查 Next.js 是否运行
echo ""
echo "[2] 检查 Next.js 服务..."
if lsof -Pi :3000 -sTCP:LISTEN -t >/dev/null; then
echo "✓ Next.js 正在运行(端口 3000"
else
echo "✗ Next.js 未运行"
echo " 请运行: cd /home/ubuntu/vf_react/src/views/AgentChat/neuratalk && npm run dev"
exit 1
fi
# 3. 测试本地访问
echo ""
echo "[3] 测试本地访问..."
if curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 | grep -q "200"; then
echo "✓ 本地访问正常 (http://localhost:3000)"
else
echo "✗ 本地访问失败"
fi
# 4. 测试 Nginx 代理
echo ""
echo "[4] 测试 Nginx 代理..."
if curl -s -o /dev/null -w "%{http_code}" https://valuefrontier.cn/ai-chat | grep -q "200\|404"; then
CODE=$(curl -s -o /dev/null -w "%{http_code}" https://valuefrontier.cn/ai-chat)
if [ "$CODE" = "200" ]; then
echo "✓ Nginx 代理正常 (https://valuefrontier.cn/ai-chat)"
else
echo "⚠ Nginx 代理返回 $CODE"
fi
else
echo "✗ Nginx 代理失败"
fi
# 5. 检查 Nginx 错误日志
echo ""
echo "[5] 最近的 Nginx 错误(如果有):"
sudo tail -n 5 /var/log/nginx/error.log | grep -i "ai-chat" || echo " 无相关错误"
echo ""
echo "========================================="
echo "诊断完成"
echo ""
echo "如果 Nginx 配置正确但仍然 404"
echo "1. 确保 Next.js 在运行"
echo "2. 检查 next.config.js 是否配置了 basePath"
echo "3. 查看 Next.js 控制台输出"
echo "========================================="