From 6b2111c81042f77a95fceabf96b29555c9766809 Mon Sep 17 00:00:00 2001 From: bunny <1319900154@qq.com> Date: Thu, 22 Aug 2024 08:33:27 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=93=A6=EF=B8=8F=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9ENGINX=E7=9A=84WebSocket=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker/nginx.conf | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/docker/nginx.conf b/docker/nginx.conf index 67110b3..7aab7ef 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -1,3 +1,8 @@ +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + server { listen 80; listen [::]:80; @@ -9,14 +14,25 @@ server { try_files $uri /index.html; } - # 后端跨域请求 + # 后端跨域请求 location ~/api/ { - proxy_pass http://192.168.3.98:1001; + proxy_pass http://192.168.3.98:8200; } - # mock 跨域 - location ~/mock/ { - proxy_pass http://192.168.3.98:1001; + # 配置WebSocket + location ~/ws/ { + # WebSocket 代理配置 + proxy_pass http://192.168.3.98:8200; # WebSocket 服务器地址和端口 + proxy_http_version 1.1; # 使用 HTTP 1.1 版本 + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_read_timeout 600s; # 保持连接的超时时间,根据需要调整 + proxy_redirect off; # 关闭重定向 + } + + # mock 跨域 + location ~/mock/ { + proxy_pass http://192.168.3.98:8200; } error_page 404 404.html;