Search code examples
node.jsapache2mod-proxy

How can I make a ProxyPass work for all pages without defining a new rule for each page


I'm very new to setting up apache configs. The docs don't make much sense to me, I have a node app running on a port that functions as a website, but I want to be able to connect to it with my domain. I've been looking around and figured I need to use a ProxyPass to redirect traffic from port 443 (https) to the port the app is running on (I already use apache for other stuff so I didn't want to switch). And it works generally, but is there a way to make only a single ProxyPass rule that will handle all pages (e.g. I go to https://example.com/ it will use https://localhost:4450/ and if I go to https://example.com/example it will use https://localhost:4450/example and for all other pages).

I would think I need a RewriteRule, but I don't really understand how I can get the page (whatever is after the first / or none) using it.


Solution

  • You simply run apache as a reverse proxy here is an example configuration:

    <VirtualHost *:443>
    
     SSLEngine On
     SSLCertificateFile /etc/apache2/ssl/file.pem
     ProxyPreserveHost On
     ServerName localhost
    
     ProxyPass / http://0.0.0.0:4450/
     ProxyPassReverse / http://0.0.0.0:4450/
    
    </VirtualHost>
    

    and you have to enable the proxy modules like that

    a2enmod proxy
    a2enmod proxy_http