Search code examples
node.jsapacheproxypass

Proxypass Apache only if port in host


I have a node app working on port 1234. Because I don't want the port number displayed anywhere, I have a ProxyPass rule in my Apache:

<VirtualHost *:80>
  ProxyPass /node http://example.com:1234
  ProxyPassReverse /node http://example.com:1234
</VirtualHost>

It's working perfectly: when I enter http://example.com/node in my browser, the expected page displays. When I enter http://example.com:1234, too, but I don't want that URL to display in my browser. That's why I put a javascript to change window.location if there is "1234" in the URL...

That's not a good solution, because the page has to load before being redirected and the user sees the port number. I'd like to know if it was possible to redirect immediately example.com:1234 to example.com/node with an Apache rule. I searched all the documentation, but the solution isn't obvious...


Solution

  • If you can't change SSO redirect URL, I would suggest the following:

    1. Run your application on different port (for example 1235)

    2. Create an additional VirtualHost listening on port 1234, and use it for redirecting to :80 with Redirect / http://example.com/

    3. Modify your existing ProxyPass url to go to port 1235