From a19e62af92fb4fd72252290e00b3421359863416 Mon Sep 17 00:00:00 2001 From: stu2not Date: Wed, 16 Sep 2026 11:19:29 +0800 Subject: [PATCH] fix(nginx): enable secure WebSocket proxying --- talkingq-url/nginx.conf | 104 ++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 69 deletions(-) diff --git a/talkingq-url/nginx.conf b/talkingq-url/nginx.conf index 3d071fa..310d0e1 100644 --- a/talkingq-url/nginx.conf +++ b/talkingq-url/nginx.conf @@ -1,20 +1,9 @@ -# 默认服务器配置已移至HTTPS服务器块 - -# 添加JavaScript MIME类型映射 -# types { -# application/javascript js mjs ts; -# text/javascript js mjs ts; -# } +# 默认服务器配置已移至 HTTPS 服务器块 server { listen 80; server_name banban.api.talkingq.com; - # location = /msUqvicTHS.txt { - # root /usr/share/nginx/html; - # } - # location / { - # root /usr/share/nginx/html; - # } + # HTTP 跳转到 HTTPS location / { return 301 https://$host$request_uri; @@ -38,12 +27,41 @@ server { access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; + # 服务号网页授权域名校验文件 + location = /MP_verify_9ixdRu6JqQrntouG.txt { + root /usr/share/nginx/html; + } + + # 旧的微信校验文件路径 location = /msUqvicTHS.txt { root /usr/share/nginx/html; } - # 将API请求转发到Java后端服务 + + # 扫普通链接二维码打开小程序:qrcode/bind 规则校验文件 + location = /qrcode/bind/HXNd3XMbPq.txt { + root /usr/share/nginx/html; + } + + # 扫普通链接二维码打开小程序:bind-qr 规则校验文件 + location = /bind-qr/msUqvicTHS.txt { + root /usr/share/nginx/html; + } + + # WebSocket 请求需要显式转发协议升级头 + location = /ws { + proxy_pass http://101.35.224.118:8080; + 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_set_header X-Forwarded-Proto $scheme; + } + + # API 请求转发到后端服务 location / { - proxy_pass http://175.24.73.253:80; + proxy_pass http://101.35.224.118:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; @@ -53,62 +71,10 @@ server { add_header Cache-Control "no-store, no-cache, must-revalidate"; expires -1; } - # # 将API请求转发到Java后端服务 - # location /api/ { - # proxy_pass http://server:8091; - # 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 X-Original-URI $request_uri; - # add_header Cache-Control "no-store, no-cache, must-revalidate"; - # expires -1; - # } - - # # 静态资源处理 - # location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|mp3|mp4|avi|pdf|txt)$ { - # proxy_pass http://node:8084; - # 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 1d; - # proxy_buffering off; - # add_header Cache-Control "public, max-age=86400"; - # } - - # # Vite特定的虚拟资源处理 - # location ~ ^(/@id|/@vite|/node_modules) { - # proxy_pass http://node:8084; - # 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; - # add_header Cache-Control "no-store, no-cache, must-revalidate"; - # expires -1; - # } - - # # WebSocket支持(Vite HMR) - # location / { - # proxy_pass http://node:8084; - # proxy_set_header Host $host; - # proxy_buffering off; - # 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 X-Original-URI $request_uri; - # add_header Cache-Control "no-store, no-cache, must-revalidate"; - # expires -1; - - # # WebSocket配置 - # proxy_http_version 1.1; - # proxy_set_header Upgrade $http_upgrade; - # proxy_set_header Connection "upgrade"; - # proxy_read_timeout 86400; - # } error_page 500 502 503 504 /50x.html; + location = /50x.html { - root /usr/share/nginx/html; + root /usr/share/nginx/html; } }