فهرست منبع

update websocket

supeng 15 ساعت پیش
والد
کامیت
9a25f56b7d
1فایلهای تغییر یافته به همراه16 افزوده شده و 1 حذف شده
  1. 16 1
      nginx.conf

+ 16 - 1
nginx.conf

@@ -5,9 +5,24 @@ server {
     root /usr/share/nginx/html;
     index index.html;
 
-    # 前端静态文件
+    # API + WebSocket 反向代理(含 WebSocket upgrade 支持)
+    location /api/ {
+        proxy_pass http://api-server:8000;
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "upgrade";
+        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_read_timeout 3600s;
+        proxy_send_timeout 3600s;
+    }
+
+    # 前端静态文件(注入运行时 API 配置,让前端走 nginx 代理而非直连 :8000)
     location / {
         try_files $uri $uri/ /index.html;
+        sub_filter_once on;
+        sub_filter '</head>' '<script>window.CONFIG={API_BASE_URL:window.location.origin};</script></head>';
     }
 
     # gzip 压缩