Apache Proxy Pass and Web Sockets
- by James
I'm using Apache with the mod_proxy module to reverse proxy my Node.js application through to port 80, so that we can access it as an internal application.
I have a file in sites-enabled which contains this:
VirtualHost *:80>
DocumentRoot /var/www/internal/
ServerName internal
ServerAlias internal
<Directory /var/www/internal/public/>
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/ retry=0
ProxyPassReverse / http://localhost:8080/
ProxyPreserveHost on
ProxyTimeout 1200
LogLevel debug
AllowEncodedSlashes on
</VirtualHost>
As I said, our application is written in Node.js and we're using socket.io to make use of web-sockets, as our application also contains realtime elements to it. The problem is, mod_proxy doesn't seem to handle web sockets and we get errors when trying to use them:
WebSocket connection to 'ws://bloot/socket.io/1/websocket/nHtTh6ZwQjSXlmI7UMua' failed: Unexpected response code: 502
How can we fix this issue and keep sockets working, as the only way we can get it working currently is to access the site via ip:port which we don't want to do.
Also, as a side question, how can I get ErrorDocument to work properly? Our error files are stored in /var/www/internal/public/error/ but they seem to get put through the proxy too?