Apache Proxy to Internal Server: Difference between revisions
initial |
info on mod-proxy |
||
| Line 1: | Line 1: | ||
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 {{code|mod_rewrite}} | 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 {{code|mod_rewrite}} and {{code|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 {{code|127.0.0.1:300}} but you want to serve it on your primary domain. | An example use-case would be, if you ran a rails application on a cPanel account listening on {{code|127.0.0.1:300}} but you want to serve it on your primary domain. | ||
If Apache has {{code|mod_rewrite}} support enabled, create a {{code|.htaccess}} file with the following contents: | If Apache has {{code|mod_rewrite}}, {{code|mod_proxy}} and {{code|mod_proxy_http}} support enabled, create a {{code|.htaccess}} file with the following contents: | ||
{{highlight|lang=text|code= | {{highlight|lang=text|code= | ||
# Prevent errors about /index.html not found | |||
DirectoryIndex disabled | DirectoryIndex disabled | ||
# Use [P] to enable proxy | |||
RewriteEngine on | RewriteEngine on | ||
RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L] | RewriteRule ^(.*)$ http://127.0.0.1:3000/$1 [P,L] | ||
| Line 13: | Line 15: | ||
With this file made, any requests made to your website will now be proxied by Apache. | With this file made, any requests made to your website will now be proxied by Apache. | ||
== See Also == | |||
* https://httpd.apache.org/docs/2.4/rewrite/proxy.html | |||
[[Category:Linux]] | [[Category:Linux]] | ||
Revision as of 07:05, 7 March 2017
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.