Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Port From Socket.IO and Change Directory

Using Apache on Ubuntu 15.04 I'm trying to effectively remove the port 3000 from the URL as well as to change the path to http://example.com/{app}/socket.io...

Using ProxyPass and ProxyPassReverse I've removed the port from the URL effectively as well as to update the server and client side accordingly to change the path.

Virtual Hosts changes:

ProxyPass /path/ http://example.com:3000/path/
ProxyPassReverse /path/ http://example.com:3000/path/

The server side changes that I made was the following:

var io = require('socket.io')(http, {path: '/path/socket.io' });
app.get('/path/', function(req, res){

and the client changes that I made was the following:

var socket = io({path: '/path/'});

Everything appeared to run smoothly until I opened up my console log and saw a plethora of GET requests while using chrome. This'll definitely kill my bandwith and I guess I somehow managed to not listen to the socket correctly which resulted in the mass amount of GET requests.

Could someone provide some guidance into what I may possibly be doing wrong?

like image 652
Josh Avatar asked Sep 14 '15 16:09

Josh


1 Answers

You're seeing a large number of requests as socket.io is falling back to long polling as Apache is not proxying the websocket connection you'll need to enable this with

mod_proxy_wstunnel 

then add

ProxyPass "/path/socker.io"  "ws://localhost:3000/"
like image 55
Xarnze Avatar answered Oct 29 '22 14:10

Xarnze