I have :
Apache
(v2.4) on port 80 of my server forwww.domain1.com
, with mod_proxy and mod_proxy_wstunnel enablednode.js + socket.io
on port 3001 of the same server.
Accessing www.domain2.com
(with port 80) redirects to 2. thanks to the method described here. I have set this in the Apache configuration:
<VirtualHost *:80>
ServerName www.domain2.com
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
ProxyPass / ws://localhost:3001/
ProxyPassReverse / ws://localhost:3001/
</VirtualHost>
It works for everything, except the websocket part : ws://...
are not transmitted like it should by the proxy.
When I access the page on www.domain2.com
, I have:
Impossible to connect ws://www.domain2.com/socket.io/?EIO=3&transport=websocket&sid=n30rqg9AEqZIk5c9AABN.
Question: How to make Apache proxy the WebSockets as well?
Did the following for a spring application running static, rest and websocket content.
The Apache is used as Proxy and SSL Endpoint for the following URIs:
Apache configuration
I use the same vHost config for the SSL configuration, no need to change anything proxy related.
Spring configuration
TODO:
Have Apache 2.4 installed (doesn't work with 2.2),
a2enmod proxy
anda2enmod proxy_wstunnel.load
Do this in the Apache config
just add two line in your file where 8080 is your tomcat running port
I finally managed to do it, thanks to this topic.
TODO:
1) Have Apache 2.4 installed (doesn't work with 2.2), and do:
2) Have
nodejs
running on port 30013) Do this in the Apache config
Note: if you have more than one service on the same server that uses websockets, you might want to do this to separate them.
With help from these answers, I finally got reverse proxy for Node-RED running on a Raspberry Pi with Ubuntu Mate and Apache2 working, using this Apache2 site config:
I also had to enable modules like this:
In addition to the main answer: if you have more than one service on the same server that uses websockets, you might want to do this to separate them, by using a custom path (*):
Node server:
Client HTML:
Apache config:
(*) Note: using the default
RewriteCond %{REQUEST_URI} ^/socket.io
would not be specific to a website, and websockets requests would be mixed up between different websites!As of Socket.IO 1.0 (May 2014), all connections begin with an HTTP polling request (more info here). That means that in addition to forwarding WebSocket traffic, you need to forward any
transport=polling
HTTP requests.The solution below should redirect all socket traffic correctly, without redirecting any other traffic.
Enable the following Apache2 mods:
Use these settings in your *.conf file (e.g.
/etc/apache2/sites-available/mysite.com.conf
). I've included comments to explain each piece:I've included an extra section for routing
/node
traffic that I find handy, see here for more info.