Apache Proxy to Internal Server: Difference between revisions
info on mod-proxy |
m Text replacement - "Category:Linux{{Navbox Linux}}" to "{{Navbox Linux}}Category:Linux" |
||
| (One intermediate revision by the same user not shown) | |||
| 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]] | {{Navbox Linux}}[[Category:Linux]] | ||
Latest revision as of 06:20, 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.