WebSocket 握手期间的 Socket.io 代码 200 错误

per*_*eus 2 apache2 socket.io

我正在将socket.io与 nodejs 和apache服务器一起使用。我得到一个代码200作为响应,我知道我必须得到101

WebSocket 连接到“wss://SITEABC.com/socket.io/?siteId=site1234567&EIO=3&transport=websocket”失败:WebSocket 握手期间出错:状态行无效

apache上的配置如下:

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/
Run Code Online (Sandbox Code Playgroud)

节点在端口 1337 上运行

小智 5

我使用 springboot 2 + stomp。就我而言,原因是在 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()

                ;
    }
Run Code Online (Sandbox Code Playgroud)