0
我使用nginx作爲反向代理,我有一個服務器作爲API和Websocket服務器。爲了使用WebScoket我需要指定一些標題:Nginx位置的API請求和一個位置的所有websockets請求
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
但是,我有一些錯誤的API請求,以解決它,我必須使用:
proxy_set_header Connection keep-alive;
但是,上面的行打破了websocket連接。所以,我可以用幾個位置修正:
location/{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /someWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /anotherWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
location /oneMoreWebSocketUrl{
proxy_pass http://0.0.0.0:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
我不喜歡,我必須對每一個網絡插座網址單獨的位置。有可能簡化它嗎?喜歡的東西:
location allWebSocketUrls_or_wss:// {
...
}
名字'websocketUrl1-3'只是例如...對不起,我不得不提到它。 – user348173
@ user348173,好,更新後 – bukkojot