Bläddra i källkod

Update:更新环境隔离配置

XieXing 3 månader sedan
förälder
incheckning
29509f691e
3 ändrade filer med 168 tillägg och 57 borttagningar
  1. 104 0
      nginx.conf
  2. 58 52
      shudao-vue-frontend/src/utils/apiConfig.js
  3. 6 5
      shudao-vue-frontend/src/utils/ticketAuth.js

+ 104 - 0
nginx.conf

@@ -0,0 +1,104 @@
+
+server {
+    listen 22000 ssl;
+   # server_name aqai.shudaodsj.com;
+    # return 301 https://$host:22000$request_uri;
+    # SSL 证书配置
+    ssl_certificate /etc/nginx/conf.d/ssl/shudaodsj.com.pem; 
+    ssl_certificate_key /etc/nginx/conf.d/ssl/shudaodsj.com.key;    # 私钥
+    client_max_body_size 50M;
+    # 推荐的 SSL 安全配置
+    #ssl_protocols TLSv1.2 TLSv1.3;
+    #ssl_ciphers ECDHE+AESGCM:DHE+AESGCM:AES256+EECDH:AES256+EDH;
+    #ssl_prefer_server_ciphers off;
+    #ssl_session_cache shared:SSL:10m;
+    #ssl_session_timeout 10m;
+    location ~ \.(zip|rar|tar|gz|bak|sql|env|git|log|ini|conf|md|txt)$ {
+        deny all;
+        return 404;
+    } 
+    
+    location /admin {
+        alias /tmp/www/dist;  # 替换为你的静态文件实际路径
+        try_files $uri $uri/ /admin/index.html; # 支持前端路由(如 Vue Router history 模式)
+    }
+
+    location /admin/api/v1 {
+        proxy_pass http://127.0.0.1:28000;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+
+    location /api/auth/login {
+        proxy_pass http://127.0.0.1:28001;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+
+    location /api/auth/check-status {
+        proxy_pass http://127.0.0.1:28001;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+
+    location /api/captcha/generate {
+        proxy_pass http://127.0.0.1:28001;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+
+    # chroma 搜索接口
+    location /api/chroma/search {
+        proxy_pass http://127.0.0.1:24000/api/search;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+ 
+    # chroma 心跳检测接口
+    location /api/chroma/health {
+        proxy_pass http://127.0.0.1:24000/api/health;  # 替换为你后端服务的实际地址和端口
+        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;
+    }
+
+    # TTS 接口
+    location /tts/voice {
+        proxy_pass http://172.16.35.50:8000/tts/voice;
+        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;
+    }
+
+    location / {
+        proxy_pass http://127.0.0.1:22001;
+        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_buffering off;
+        proxy_cache off;
+        proxy_http_version 1.1;
+
+        # proxy_set_header Connection '';
+        # chunked_transfer_encoding on;
+
+        # 超时设置
+        proxy_read_timeout 3600s;
+        proxy_send_timeout 3600s;
+    }
+}

+ 58 - 52
shudao-vue-frontend/src/utils/apiConfig.js

@@ -3,121 +3,127 @@
  * 统一管理所有需要环境隔离的 API 地址配置
  * 
  * 环境说明:
- * - 开发/测试环境 (npm run dev): 通过 vite 代理转发到本地服务
- * - 生产环境 (npm run build): 通过 nginx 代理访问
+ * - 本地环境 (localhost/127.0.0.1): npm run dev,通过 vite 代理
+ * - 测试环境 (172.16.29.101): npm run build 部署到测试服务器
+ * - 生产环境 (aqai.shudaodsj.com): npm run build 部署到生产服务器
  * 
- * 生产环境 nginx 代理路径:
+ * nginx 代理路径(测试/生产环境)
  * - /apiv1 → 系统后端 (shudao-go-backend)
  * - /chatwithai/ → AI对话服务后端 (ReportGenerator等)
  * - /auth → 认证网关服务
  * - /tts → TTS语音合成服务
  */
 
-const isDev = import.meta.env.DEV
+// ==================== 环境检测 ====================
+
+const hostname = typeof window !== 'undefined' ? window.location.hostname : 'localhost'
+
+/** 本地开发环境 */
+export const isLocal = hostname === 'localhost' || hostname === '127.0.0.1'
+
+/** 测试环境 */
+export const isTest = hostname === '172.16.29.101'
+
+/** 生产环境 */
+export const isProd = hostname === 'aqai.shudaodsj.com'
+
+/** 当前环境名称 */
+export const ENV = isLocal ? 'local' : isTest ? 'test' : 'prod'
+
+/**
+ * 根据环境获取配置值
+ * @param {Object} config - { local: value, test: value, prod: value }
+ * @returns 当前环境对应的值
+ */
+export function getEnvConfig(config) {
+  return config[ENV] ?? config.prod
+}
 
 // ==================== 服务地址配置 ====================
 
 /**
  * 系统后端服务 (shudao-go-backend)
- * 开发环境: 127.0.0.1:22001 (通过 vite 代理)
- * 生产环境: /apiv1 (通过 nginx 代理)
+ * 所有环境统一使用 /apiv1(本地通过vite代理,测试/生产通过nginx代理)
  */
 export const BACKEND_API_PREFIX = '/apiv1'
 
 /**
  * AI对话服务 - 报告生成 (ReportGenerator)
- * 开发环境: 127.0.0.1:28002 (通过 vite 代理)
- * 生产环境: /chatwithai/api/v1 (通过 nginx 代理)
+ * 本地/测试: /api/v1 (通过代理)
+ * 生产: /chatwithai/api/v1 (通过 nginx 代理)
  */
-export const REPORT_API_PREFIX = isDev 
-  ? '/api/v1' 
-  : '/chatwithai/api/v1'
+export const REPORT_API_PREFIX = getEnvConfig({
+  local: '/api/v1',
+  test: '/api/v1',
+  prod: '/chatwithai/api/v1'
+})
 
 /**
  * AI对话服务 - SSE 流式
- * 开发环境: 127.0.0.1:28002 (通过 vite 代理)
- * 生产环境: /chatwithai/api/v1 (通过 nginx 代理)
  */
-export const SSE_API_PREFIX = isDev 
-  ? '/api/v1' 
-  : '/chatwithai/api/v1'
+export const SSE_API_PREFIX = REPORT_API_PREFIX
 
 /**
  * 认证网关服务 (4A统一API网关)
- * 开发环境: 127.0.0.1:28004 (通过 vite 代理)
- * 生产环境: /auth/api (通过 nginx 代理)
+ * 本地/测试: /api (通过代理)
+ * 生产: /auth/api (通过 nginx 代理)
  */
-export const AUTH_GATEWAY_URL = isDev 
-  ? '/api' 
-  : '/auth/api'
+export const AUTH_GATEWAY_URL = getEnvConfig({
+  local: '/api',
+  test: '/api',
+  prod: '/auth/api'
+})
 
 /**
  * TTS 语音合成服务
- * 开发环境: 172.16.29.101:22000 (通过 vite 代理)
- * 生产环境: /tts (通过 nginx 代理)
+ * 本地: /api/tts (通过 vite 代理)
+ * 测试/生产: /tts (通过 nginx 代理)
  */
-export const TTS_API_PREFIX = isDev 
-  ? '/api/tts' 
-  : '/tts'
+export const TTS_API_PREFIX = getEnvConfig({
+  local: '/api/tts',
+  test: '/tts',
+  prod: '/tts'
+})
 
 /**
  * 音频转录服务 (语音转文字)
- * 开发/测试环境: 172.16.35.50:8000 (直连)
- * 生产环境: https://aqai.shudaodsj.com:22000 (直连)
+ * 本地/测试: 内网直连
+ * 生产: 外网地址
  */
-export const AUDIO_TRANSCRIPTION_BASE = isDev 
-  ? 'http://172.16.35.50:8000' 
-  : 'https://aqai.shudaodsj.com:22000'
+export const AUDIO_TRANSCRIPTION_BASE = getEnvConfig({
+  local: 'http://172.16.35.50:8000',
+  test: 'http://172.16.35.50:8000',
+  prod: 'https://aqai.shudaodsj.com:22000'
+})
 
 // ==================== 便捷函数 ====================
 
-/**
- * 获取业务 API 路径前缀
- */
 export function getApiPrefix() {
   return BACKEND_API_PREFIX
 }
 
-/**
- * 获取报告 API 前缀
- */
 export function getReportApiPrefix() {
   return REPORT_API_PREFIX
 }
 
-/**
- * 获取 SSE API 前缀
- */
 export function getSSEApiPrefix() {
   return SSE_API_PREFIX
 }
 
-/**
- * 获取认证网关 API 前缀
- */
 export function getAuthGatewayUrl() {
   return AUTH_GATEWAY_URL
 }
 
-/**
- * 获取 TTS API 前缀
- */
 export function getTTSApiPrefix() {
   return TTS_API_PREFIX
 }
 
-/**
- * 获取音频转录服务地址
- */
 export function getAudioTranscriptionBase() {
   return AUDIO_TRANSCRIPTION_BASE
 }
 
 /**
  * 构建完整的 API URL
- * @param {string} path - API 路径(例如:'/report/export')
- * @param {string} prefix - API 前缀,默认使用业务后端
- * @returns {string} 完整的 API URL
  */
 export function buildApiUrl(path, prefix = BACKEND_API_PREFIX) {
   const normalizedPath = path.startsWith('/') ? path : `/${path}`

+ 6 - 5
shudao-vue-frontend/src/utils/ticketAuth.js

@@ -3,11 +3,12 @@
  * 处理从门户传递过来的票据,获取访问令牌
  */
 
-import { getAuthGatewayUrl } from './apiConfig'
+import { getAuthGatewayUrl, isLocal, isTest, isProd } from './apiConfig'
 
 // 从统一配置获取认证服务地址
-const isDev = import.meta.env.DEV
 const AUTH_GATEWAY_URL = getAuthGatewayUrl()
+// 本地和测试环境使用默认票据
+const useDefaultTicket = isLocal || isTest
 const TICKET_GET_API = `${AUTH_GATEWAY_URL}/ticket/get`
 const TICKET_PROCESS_API = `${AUTH_GATEWAY_URL}/ticket/process`
 
@@ -558,9 +559,9 @@ export async function handleTicketAuth() {
         return { success: true, token: tokenData, fromCache: true }
       }
       
-      // 开发/测试模式:自动获取默认票据
-      if (isDev) {
-        addDebugLog('info', '🔧 开发模式:自动获取默认用户票据')
+      // 本地/测试环境:自动获取默认票据
+      if (useDefaultTicket) {
+        addDebugLog('info', '🔧 本地/测试环境:自动获取默认用户票据')
         try {
           ticket = await getDefaultTicket()
           addDebugLog('success', '✅ 获取默认票据成功')