安全的websocket连接有问题。我有运行在https上的应用程序,其中突变和查询有效,但无法建立wss连接:/当我在不安全的连接(http)上运行react应用程序并使用ws则一切正常。我不确定是什么导致了这个问题--可能是nginx代理,可能是nestjs graphql config,也可能是react apollo客户端。简而言之:
让服务器使用nginx,并配置证书。我的域的服务器代理子目录到某个应用程序(在docker容器中运行,并在端口3000上公开):
server {
listen 443 ssl;
server_name mydomain.com
[...cert configs...]
location /one/of/app/ {
proxy_pass http://localhost:3000/
}
}正如我所提到的,网站使用安全连接工作,但wss连接失败。我没有在服务器或客户端做任何额外的事情-所有配置都相同,而是uri (https,wss,而不是http,ws)。在不安全的连接上,使用ws:// websocket工作。有什么建议吗?
完全错误:
WebSocket connection to 'wss://mydomain.com/one/of/app/graphql' failed: Error during WebSocket handshake: Unexpected response code: 400发布于 2020-12-19 06:19:00
在这里找到解决方案:https://stackoverflow.com/a/48096141/13514288
新增api (/one/of/app/) nginx proxy额外头部:
location /one/of/app/ {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:3000/
}https://stackoverflow.com/questions/65364509
复制相似问题