[Bug] 宝塔Nginx反代添加WebSocket参数后,更新模板还是出现undefined 1006
LD-KiLLer opened this issue · comments
Verify steps
- Tracker 我已经在 Issue Tracker 中找过我要提出的问题
- Latest 我已经使用 最新源码 测试过,问题依旧存在
- Core 这是 QD 框架存在的问题,并非我所使用的 QD 早期版本(如 20210628及之前版号 等)或模板的特定问题
- Meaningful 我提交的不是无意义的 催促更新或修复 请求
QD Version
20230821
Bug on OS
Linux
Bug on Platform
Docker/Linux 64位
To Reproduce
我根据说明里常见问题issue#423在宝塔Nginx里添加了WebSocket关键配置参数
#PROXY-START/
location /
{
proxy_pass http://127.0.0.1:5700;
# WebSocket 关键配置 开始
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# WebSocket 关键配置 结束
# 其他可选配置 开始
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-END/
但是访问公共模板还是出现
错误代码:undefined,
错误原因:undefined
错误代码:1006,
在内网里使用IP+host访问可以正常更新模板库,查看chrome的开发工具提示:
WebSocket connection to 'wss://***.***.com:8443/subscribe/1/updating/' failed:
update_req @ (索引):212
(匿名) @ (索引):190
然后我尝试在Nginx的反代代码里单独添加wss的配置也是一样的问题
#PROXY-START/
location /
{
proxy_pass http://127.0.0.1:5700;
# WebSocket 关键配置 开始
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# WebSocket 关键配置 结束
# 其他可选配置 开始
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 /wss
{
proxy_pass http://127.0.0.1:5700;
# WebSocket 关键配置 开始
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# WebSocket 关键配置 结束
# 其他可选配置 开始
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-END/
Describe the Bug
我根据说明里常见问题issue#423在宝塔Nginx里添加了WebSocket关键配置参数
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
但是访问公共模板还是出现
错误代码:undefined,
错误原因:undefined
错误代码:1006,
QD config
No response
QD log
Docker日志里没有见到报错
[I 230904 11:18:19 tornado.access web:2344] 200 GET /subscribe/1/ (112.117.40.140) 92.91ms
[I 230904 11:18:19 tornado.access web:2344] 200 GET /subscribe/1/ (112.117.40.140) 84.11ms
[I 230904 11:18:19 tornado.access web:2344] 200 GET /static/img/body.jpg (112.117.40.140) 1.93ms
[I 230904 11:18:19 tornado.access web:2344] 200 GET /static/img/header.jpg (112.117.40.140) 3.97ms
[W 230904 11:18:20 tornado.access web:2344] 403 GET /subscribe/1/updating/ (112.117.40.140) 1.89ms
### Expected behavior
望大佬帮忙看看这一问题,拜谢
### Screenshots
![Snipaste_2023-09-04_11-22-27](https://github.com/qd-today/qd/assets/72300642/79b75ce9-1f89-4cd4-91c3-33f95182f986)
![Snipaste_2023-09-04_11-22-51](https://github.com/qd-today/qd/assets/72300642/3f87be06-7539-4b1c-af0e-b79f63baa832)
![Snipaste_2023-09-04_11-23-57](https://github.com/qd-today/qd/assets/72300642/e9bee1c3-f7ad-4dc5-82fe-d46a80cdc7bc)
![Snipaste_2023-09-04_11-25-16](https://github.com/qd-today/qd/assets/72300642/161b15b7-6b5d-4e6f-96ce-871aec0835de)
请更新到最新源码版本 dev 容器尝试
更新至dev容器后反复出现“更新公共模板成功,正在跳转,请稍后......”,并且公共模板的网页不停在刷新(猫眼和Edge都是一样的情况)。
使用内网IP登录(未经过Nginx反代)可以正常访问公共模板页面,并且没有正在调整不停刷新页面的情况出现。
如果方便,麻烦贴一下完整的nginx配置
因为是使用了宝塔面板的Nginx,代码分为两段:
- 网站的配置文件:
server
{
listen 80;
listen 443 ssl http2;
server_name qiandao.xxxxxx.com;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/qiandao.xxxxxx.com;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
if ($server_port !~ 443){
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/qiandao.xxxxxx.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/qiandao.xxxxxx.com/privkey.pem;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
error_page 497 https://$host$request_uri;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
#清理缓存规则
location ~ /purge(/.*) {
proxy_cache_purge cache_one $host$1$is_args$args;
#access_log /www/wwwlogs/qiandao.xxxxxx.com_purge_cache.log;
}
#引用反向代理规则,注释后配置的反向代理将无效
include /www/server/panel/vhost/nginx/proxy/qiandao.xxxxxx.com/*.conf;
include enable-php-00.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/qiandao.xxxxxx.com.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
#禁止在证书验证目录放入敏感文件
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
return 403;
}
access_log /www/wwwlogs/qiandao.xxxxxx.com.log;
error_log /www/wwwlogs/qiandao.xxxxxx.com.error.log;
}
- 网站的反向代理:
#PROXY-START/
location / {
proxy_pass http://127.0.0.1:8923;
# WebSocket 关键配置 开始
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# WebSocket 关键配置 结束
#Nginx webSocket 保持长连接 开始
proxy_connect_timeout 300s; #配置点1
proxy_read_timeout 600s; #配置点2,如果没效,可以考虑这个时间配置长一点
proxy_send_timeout 300s; #配置点3
#Nginx webSocket 保持长连接 结束
#Set Nginx Cache 开始
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 301 302 30m;
#Set Nginx Cache 结束
# 其他可选配置 开始
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-END/
配置环境是一台是用PVE8.0的软路由,搭建了一个Ubuntu22的虚拟机,然后在这台Ubuntu虚拟机上安装了宝塔面板8.0.1,同时使用Docker搭建了签到服务的dev版本。然后通过域名+端口的方式访问签到服务。
#Set Nginx Cache 开始
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 301 302 30m;
#Set Nginx Cache 结束
大概是nginx 缓存问题
#Set Nginx Cache 开始
proxy_ignore_headers Set-Cookie Cache-Control expires;
proxy_cache cache_one;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 304 301 302 30m;
#Set Nginx Cache 结束
把这段删掉试试
果然是Nginx缓存的问题,注释或者删除掉大佬说的这段后,就没有反复刷新的情况出现了,拜谢、拜谢
记录一下,Docker hub 里面的 20230821 latest 版本,跟这位大兄弟一样的问题,不知道是不是不支持wss的原因,切换 dev 版本后正常了。