WebSocket connection failed: Error during WebSocket handshake: Unexpected response code: 400

后端 未结 16 1462
攒了一身酷
攒了一身酷 2020-12-04 21:08

I am trying to integrate Socket.io with Angular and I\'m having difficulties making a connection from the client-side to the server. I\'ve looked through other related quest

16条回答
  •  佛祖请我去吃肉
    2020-12-04 21:35

    I had faced same issues, I refined apache2 virtual host entery and got success.

    Note: on server I had succesful installed and working on 9001 port without any issue. This guide line for apache2 only no relavence with nginx, this answer for apache2+etherpad lovers.

    
      ServerName pad.tejastank.com
      ServerAlias pad.tejastank.com
      ServerAdmin snippetbucket@gmail.com
    
      LoadModule  proxy_module         /usr/lib/apache2/modules/mod_proxy.so
      LoadModule  proxy_http_module    /usr/lib/apache2/modules/mod_proxy_http.so
      LoadModule  headers_module       /usr/lib/apache2/modules/mod_headers.so
      LoadModule  deflate_module       /usr/lib/apache2/modules/mod_deflate.so
    
      ProxyVia On
      ProxyRequests Off
      ProxyPreserveHost on
    
        
            ProxyPass http://localhost:9001/ retry=0 timeout=30
            ProxyPassReverse http://localhost:9001/
        
        
            # This is needed to handle the websocket transport through the proxy, since
            # etherpad does not use a specific sub-folder, such as /ws/ to handle this kind of traffic.
            # Taken from https://github.com/ether/etherpad-lite/issues/2318#issuecomment-63548542
            # Thanks to beaugunderson for the semantics
            RewriteEngine On
            RewriteCond %{QUERY_STRING} transport=websocket    [NC]
            RewriteRule /(.*) ws://localhost:9001/socket.io/$1 [P,L]
            ProxyPass http://localhost:9001/socket.io retry=0 timeout=30
            ProxyPassReverse http://localhost:9001/socket.io
        
    
    
      
        Options FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
      
    
    

    Advance tips: Please with help of a2enmod enable all mod of apache2

    Restart apache2 than will get effect. But obvious a2ensite to enable site required.

提交回复
热议问题