Apache Proxy to Internal Server: Difference between revisions

From Leo's Notes
This page was last edited on 1 September 2019, at 05:07.
info on mod-proxy
m Text replacement - "Category:Linux" to "Category:Linux{{Navbox Linux}}"
Line 19: Line 19:
* https://httpd.apache.org/docs/2.4/rewrite/proxy.html
* https://httpd.apache.org/docs/2.4/rewrite/proxy.html


[[Category:Linux]]
[[Category:Linux]]{{Navbox Linux}}

Revision as of 05:07, 1 September 2019

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 and mod_proxy modules 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, mod_proxy and mod_proxy_http support enabled, create a .htaccess file with the following contents:

# Prevent errors about /index.html not found
DirectoryIndex disabled

# Use [P] to enable proxy
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.

See Also