Apache Proxy to Internal Server

From Leo's Notes
Revision as of 06:53, 7 March 2017 by Leo (talk | contribs) (initial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 7 March 2017, at 06:53.

Suppose you are running a server/daemon as a normal user on a very high port number but you wish to serve the contents on an existing Apache web server. You can use Apache's mod_rewrite module to proxy any requests made to Apache to your internal service.

An example use-case would be, if you ran a rails application on a cPanel account listening on 127.0.0.1:300 but you want to serve it on your primary domain.

If Apache has mod_rewrite support enabled, create a .htaccess file with the following contents:

DirectoryIndex disabled

RewriteEngine on
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L]

With this file made, any requests made to your website will now be proxied by Apache.