3 Aug 2015

Configuring Virtual Hosts as Proxy Server on Linux Mint with Apache2.4

Configuring Virtual Hosts as Proxy Server on Linux Mint with Apache2.4

To configure a virtual host as proxy server we use Apache as a virtual host and as a proxy server to redirect requests to JBOSS application server. In this regard we separate the  whole process into multiple steps as below

  1. Installing Apache
  2. Configuring Virtual Hosts in Apache
  3. Enabling and configuring Proxy server in Apache

1. Installing Apache

              As specified in the header we are doing the configuration in Mint, so we user apt-get to install Apache2 as below

#apt-get install apache2

2. Configuring Virtual Hosts in Apache

        Copy the following block in to the file "/etc/apache2/sites-enabled/000-default.conf"

         <VirtualHost *:80>
                  ServerName www.example.com
                  ServerAdmin webmaster@localhost
                  DocumentRoot /var/www/html
         </VirtualHost>

      "*" in the above configuration implies all the requests to this host i.e all the requests to this server with 80 port number will be served by this virtual host.
      "ServerName" directive specifies the name server identifies itself with.

3. Enabling and configuring Proxy server in Apache

                To enable Proxy in Apache use the command a2enmod as shown below

#a2enmod
        The above line will show you modules that are supported by Apache and lets you select the modules to be enabled. So enter the following options to enable 
proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html

              To configure the above Virtual host as proxy change the Virtual Host block to the following


<VirtualHost *:80>
    ServerName www.example.com
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
   
    ProxyPreserveHost On
    ProxyPass /examples http://localhost:8080/examples
    ProxyPassReverse /examples http://localhost:8080/examples 
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
         "ProxyPreserveHost" directive uses the incoming request's header for proxy redirections.
         "ProxyPass" directive maps /examples to our local server URL "http://localhost:8080/examples"
          "ProxyPassReverse" adjusts the response header URL sent from the reverse proxied server.


Reference docs:

https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension

https://httpd.apache.org/docs/2.2/vhosts/examples.html

No comments:

Post a Comment

Note: only a member of this blog may post a comment.