Using socket.io with nodejs on a server with apache as a reverse proxy

前端 未结 3 411
执笔经年
执笔经年 2021-01-02 06:08

I\'m attempting to use Node.js with Socket.IO to faciliate messaging between the browser and client, following the guide.

However, I had to setup Node reverse-proxie

3条回答
  •  梦毁少年i
    2021-01-02 07:02

    If anybody is interested, only this worked for me. Replace port 3000 with your Nodejs port

    Apache 2.2.14 inside your VirtualHost

        
          
            Order allow,deny
            allow from all
          
        
    
        RewriteEngine on
    
        RewriteCond %{QUERY_STRING} transport=polling
        RewriteRule /(.*)$ http://localhost:3001/$1 [P]
    
        ProxyRequests off
        ProxyPass /socket.io/ ws://localhost:3001/socket.io/
        ProxyPassReverse /socket.io/ ws://localhost:3001/socket.io/
    

    Client side connection:

      var myIoSocket = io.connect($location.protocol() + '://' + $location.host(), {path: '/socket.io'});
    

    No need to change anything on Node.js side.

提交回复
热议问题