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?
For me it works after adding only one line in httpd.conf as below (bold line).
Apache version is 2.4.6 on CentOS.
For "polling" transport.
Apache side:
Client side:
May be will be useful. Just all queries send via ws to node
My setup:
Apache 2.4.10 (running off Debian) NodeJS (version 4.1.1) App running on port 3000 that accepts WebSockets at path /api/ws
As mentioned above by @Basj, make sure a2enmod proxy and ws_tunnel are enabled.
This is a screengrab of the Apache conf file that solved my problem:
Hope that helps.
Instead of filtering by URL, you can also filter by HTTP header. This configuration will work for any web applications that use websockets, also if they are not using socket.io:
User this link for perfact solution for ws https://httpd.apache.org/docs/2.4/mod/mod_proxy_wstunnel.html
You have to just do below step..
Got to /etc/apache2/mods-available
Step...1
Enable mode proxy_wstunnel.load by using below command
$a2enmod proxy_wstunnel.load
Step...2
Goto /etc/apache2/sites-available
and add below line in your .conf file inside virtual host
ProxyPass "/ws2/" "ws://localhost:8080/"
ProxyPass "/wss2/" "wss://localhost:8080/"
Note : 8080 mean your that your tomcat running port because we want to connect "ws" where our War file putted in tomcat and tomcat serve apache for "ws". thank you
My Configuration
ws://localhost/ws2/ALLCAD-Unifiedcommunication-1.0/chatserver?userid=4 =Connected