2015/04/09

How to configure Apache reverse proxy



Apache's reverse proxy is an act of an Apache webserver providing content from other webserver transparently. This is useful in many instances such as caching and mirroring, but it's mostly used to serve websites that are hosted behind NAT or a firewall. A reverse proxy server routes connection addressed to the internal server, and the client sees the reverse proxy server itself as the origin server.


For example, Apache can be configured to serve URL's such as http://www.example.com/webapp to actually get the content from http://192.168.0.10/myapp, which is hosted from an internal network. This happens transparently and the user initially requesting http://www.example.com/webapp need not to be aware of what happens in the background.




Enable proxy modules




Apache require 2 modules enabled for this reverse proxy to work. These modules are proxy and proxy_http. To enable them, run the following command at the terminal.
sudo a2enmod proxy_http

That will enable both proxy and proxy_http, as proxy module is actually a dependency to the proxy_http module. This is confirmed by the output of the above command.
Considering dependency proxy for proxy_http:
Enabling module proxy.
Enabling module proxy_http.

Once the module is enabled, you can start configuring the reverse proxy settings.


Configure reverse proxy




From the previous example, we would like our public facing webserver at http://www.example.com to host our internal site of http://192.168.0.10/myapp to be available as http://www.example.com/webapp

You'll need to add the following lines to your Apache's configuration file.
For Ubuntu, the file could be /etc/apache2/sites-enabled/000-default

ProxyRequests Off

ProxyPass /webapp http://192.168.0.10/myapp
ProxyPassReverse /webapp http://192.168.0.10/myapp


Restart Apache




For the changes to take effect, the Apache webserver need to be re-started. Run the following command at the terminal to do that.
sudo /etc/init.d/apache2 restart


ليست هناك تعليقات:

إرسال تعليق