无效的 websocket 升级

问题描述 投票:0回答:1

我在 NiceGUI 和 Nginx 的帮助下在 VPS 上设置了服务器。请求通过子域并正确路由:服务器接收请求并打印 html 元素。

但是,在使用 websockets 时,我可以在服务器上看到以下错误:

ERROR:engineio.server:Invalid websocket upgrade (further occurrences of this error will be logged with level INFO)

相反,我的浏览器显示

manager.js:108 WebSocket connection to 'wss://{I-hid-this}/_nicegui_ws/socket.io/?client_id=ce259c07-9781-4739-9faa-051f24e911bd&EIO=4&transport=websocket' failed

相同的设置,运行它

on_air
完美运行

这是我的子域的 nginx 配置:

server {
    listen 80;
    server_name {I-hid-this};

    location / {
        proxy_pass http://127.0.0.1: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;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
server{
        # SSL configuration
        listen 443 ssl;
        server_name {I-hid-this};
        ssl_certificate /etc/nginx/ssl/{I-hid-this}_ssl_certificate.cer;
        ssl_certificate_key /etc/nginx/ssl/_.{I-hid-this}_private_key.key;

        location / {
                proxy_pass http://127.0.0.1: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;
                proxy_set_header X-Forwarded-Proto $scheme;
        }

}

我尝试在额外的端口上添加套接字,但没有什么区别。

我遇到的主要问题是我找不到有关已发布错误的任何具体文档。

更新:我记录了收到的标头,值得注意的是

transport
设置为
websocket
,但是没有传递
HTTP_UPGRADE
,这就是杀死逻辑的原因。此外,似乎我的本地工作服务器收到
ws
作为方案,而我的非工作 VPS 收到
https
。我希望这会有所帮助。

python websocket web-frameworks nicegui
1个回答
0
投票

我通过将以下配置添加到我的 nginx 配置文件中解决了这个问题:

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

感谢此来源:https://www.nginx.com/blog/websocket-nginx/

© www.soinside.com 2019 - 2024. All rights reserved.