websocket Handshake failed due to invalid Upgrade header

Posted 悟能的师兄

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了websocket Handshake failed due to invalid Upgrade header相关的知识,希望对你有一定的参考价值。

解决办法:在 Nginx ,location 中添加以下代码:

 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection  "upgrade";

完整的nginx配置信息如下:

server 
    listen 80;
    server_name localhost;

    #my java server config
	location /website/ 
		add_header 'Access-Control-Allow-Origin' '*';
		proxy_pass http://127.0.0.1:8848/;
		proxy_set_header   Host             $host;
		proxy_set_header   X-Real-IP        $remote_addr;						
		proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		
		# enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection  "upgrade";
	

}

以上是关于websocket Handshake failed due to invalid Upgrade header的主要内容,如果未能解决你的问题,请参考以下文章

报错nginx failed error: during websocket handshake

websocket Handshake failed due to invalid Upgrade header

websocket Handshake failed due to invalid Upgrade header

js websocket客户端连接docker容器失败 failed: Connection closed before receiving a handshake response

信任 Websocket SSL - 收到致命警报:handshake_failure

Error during WebSocket handshake 403