gpt4 book ai didi

angularjs - 为什么angular-socket-io用 'Error during WebSocket handshake: Unexpected response code: 400?'提示

转载 作者:行者123 更新时间:2023-12-03 11:59:59 24 4
gpt4 key购买 nike

我有一个从http移到https的节点应用程序(全 Angular 堆栈)。一切正常,但套接字连接无效。我想念什么?

在socketFactory中,我有:

var ioSocket = io('https://localhost', {
path: '/socket.io-client'
});

我认为已经导致传输使用“wss://”。 https连接都很好。有一段时间,我认为Nginx不能正确处理代理。但是那是不正确的。

接下来,我将形式从“ https://locahost”更改为“ https://xxx_actual_server_url_xxxx”,现在在初始页面重新加载后一切正常。我怎么看到一个:
WebSocket connection to 'wss://xxx_actual_server_url_xxxx/
socket.io-client/?EIO=3&transport=websocket&sid=Y4_cKvyTERz_F1ZCAAAK'
failed: Error during WebSocket handshake: Unexpected response code: 400

是什么原因造成的?以及如何解决它?我没有做任何负载平衡或其他任何事情,只是使用“grunt serve”运行开发服务器。有什么想法吗?

谢谢!

最佳答案

经过大量搜索和查找,我发现在将套接字与nginx一起使用时,我需要在代理中添加以下内容:

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

做到这一点,现在一切都很好。希望这会帮助其他人。
使用nginx转发代理的完整参数集为:
 location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_pass https://127.0.0.1:9000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

感谢那些看着这个的人!

关于angularjs - 为什么angular-socket-io用 'Error during WebSocket handshake: Unexpected response code: 400?'提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29811399/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com