我正在使用带有nodejs和apache服务器的 socket.io。我得到一个代码 200 作为响应,我知道我必须得到 101。
WebSocket 连接到 "wss://SITEABC.com/socket.io/?siteId=site1234567&EIO=3&transport=websocket" 失败:WebSocket 握手期间出错:状态行无效
apache 上的配置是 folowing:
RewriteCond %{HTTP:Upgrade} ^Websocket [NC]
RewriteCond %{HTTP:CONNECTION} ^Upgrade$ [NC]
RewriteRule .* ws://localhost:1337/{REQUEST_URI} [P]
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
ProxyPass / http://localhost:1337/
ProxyPassReverse / http://localhost:1337/
ProxyPass /socket.io/ http://localhost:1337/socket.io/
节点在端口 1337 上运行
我使用弹簧靴2 +跺脚。就我而言,原因是在WebSocketConfig中,必须删除.withSockJS
。
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/ws").setAllowedOrigins("*")
.addInterceptors(new HandshakeInterceptor())
//--> important must remove,or 200 error.
//.withSockJS()
;
}
这意味着您的请求不会代理到 WebSocket 处理程序,而是代理到返回 200 的其他路由。
您应该检查您的 WebSocket 处理程序。