I know there are several questions like this but i can't find one solving my problem for a project which is not in the server root. I have the following situation: I have an Apache server which runs several projects like:
0.0.0.0/project1
0.0.0.0/project2
I added a node.js project let's call it nodeproject
. With ProxyPass I am passing requests made to 0.0.0.0/nodeproject
to 0.0.0.0:8080
where my node server is running. This is all working fine except the websocket configuration for socket.io.
In my /etc/apache2/apache2.conf
file i placed this code to do the proxying. mod_proxy_wstunnel
is enabeld Which i basically copied from here.
ProxyRequests off
ProxyVia on
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/nodeproject/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
ProxyPass /nodeproject/socket.io http://localhost:8080/socket.io
ProxyPassReverse /nodeproject/socket.io http://localhost:8080/socket.io
<Location /nodeproject>
ProxyPass http://localhost:8080
ProxyPassReverse http://localhost:8080
</Location>
The failing request looks like this:
ws://0.0.0.0/nodeproject/socket.io/?EIO=3&transport=websocket&sid=MDuVcHmt3T1sa8ruAAAa
and i get a Bad Request 400 response.
I am not an expert in configuring this kind of stuff where did I go wrong?
Thanks in advance!
You shouldn't put the rewrite conditional in the /etc/apache2/apache2.conf
, but in the virtual host directive in /etc/apache2/sites-available/000-project-whatever.conf
.
Here's an example from one of my own little projects.
<VirtualHost *:80>
ServerName sockey.api
ServerAdmin webmaster@localhost
DocumentRoot /var/www/sockey.api
<Directory /var/www/sockey.api>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorDocument 404 /index.html
ErrorLog ${APACHE_LOG_DIR}/sockey.api.error.log
CustomLog ${APACHE_LOG_DIR}/sockey.api.access.log combined
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:8081/$1 [P,L]
ProxyPass /socket.io http://localhost:8081/socket.io
ProxyPassReverse /socket.io http://localhost:8081/socket.io
</VirtualHost>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With