Handshake failed due to invalid Upgrade header: null 解決方案以及連接60s,信息不交互,連接斷開
1. 問題背景:因為后端用了nginx代理,所以websocket連接的過程中報錯:Handshake failed due to invalid Upgrade header: null
2. 解決辦法:在nginx中添加以下代碼:
啟用支持websocket連接
文章來源:http://www.zghlxwxcb.cn/news/detail-534255.html
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 3600s; // 超時設(shè)置
說明:proxy_http_version: 1.1;
(告訴nginx使用HTTP/1.1通信協(xié)議,這是websocket必須要使用的協(xié)議)proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
(告訴nginx,當它想要使用Websocket時,響應(yīng)http升級請求)proxy_read_timeout 3600s;
( 超時設(shè)置, 如果不設(shè)置的話,默認60s,60s內(nèi)沒有信息交互,將自動斷開
)
代碼截圖:文章來源地址http://www.zghlxwxcb.cn/news/detail-534255.html
到了這里,關(guān)于Handshake failed due to invalid Upgrade header: null 解決方案以及連接60s,信息不交互,連接斷開的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!