|
@@ -5,9 +5,24 @@ server {
|
|
|
root /usr/share/nginx/html;
|
|
root /usr/share/nginx/html;
|
|
|
index index.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 / {
|
|
location / {
|
|
|
try_files $uri $uri/ /index.html;
|
|
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 压缩
|
|
# gzip 压缩
|