6

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?

Josh
  • 123
  • 21
  • Maybe socket.io cant connect to websocket server, it send many request to it to reconnect, fix your script link to socket.io js – trquoccuong Dec 23 '15 at 05:49
  • @trquoccuong Can you elaborate? Which link should I fix? The one on the clientside? – Josh Dec 26 '15 at 05:39
  • Why do you have app.get('/path') ? – Makubex Dec 29 '15 at 18:36
  • @Makubex In order to specify the path of the directory of where the app will be located – Josh Dec 29 '15 at 18:39
  • Well.. may be it's intercepting your socket connection and it's not upgrading to websockets and hence showing up as GET requests, both of them have /path – Makubex Dec 29 '15 at 18:42
  • @Makubex If I don't specify app.get('/path') and I just leave it at ('/'), then the app will be hosted directly on the domain at www.example.com:3000/ rather than www.example.com:3000/path/. Also, it works just fine if I include the port in the URL, but if I don't, that's where I run into problems – Josh Dec 29 '15 at 18:46
  • The 'app' here is your entire site or socket.io stuff? – Makubex Dec 29 '15 at 18:54
  • @Makubex SocketIO stuff, simply for notifications – Josh Dec 29 '15 at 18:54
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/99241/discussion-between-makubex-and-josh). – Makubex Dec 29 '15 at 19:02

1 Answers1

1

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/"
Xarnze
  • 11
  • 1