May 28, 2016 · apache proxy virtualhost guide setup ·

HOWTOs: Setup an apache proxy web server [updated]

Updated 06/08/2016 - Added rewrite rule and turned off open proxy requests and block off proxy attacks on your webserver.

If you are looking to quickly setup an apache web server to act as a proxy between your web traffic and application servers then this guide is for you. Note, this is for simple websites (blogging) that use only HTTP. We will not cover HTTPS proxy traffic. Setting up a web server proxy between the web and your server is for future extensibility, such as setting up maintenance pages, load balancing or complex redirect rules for specific data the web page might require from the client.

1 . Generate a VM via AWS, DigitalOcean, etc.. with an Ubuntu OS.
2 . Update the OS: sudo apt-get update
3 . Install Apache: sudo apt-get install apache2
4 . Apache will be located at: /etc/apache2/
5 . Install apache modules that we will need:
sudo a2enmod proxy sudo a2enmod proxy_http 6 . Apache provides a default example VirtualHost. We will ignore this and create our own.
7 . If your site is called then we will create a new directory under /var/www/ : sudo mkdir /var/www/myblog
8 . Now lets create the virtualhost by copying the example apache virtualhost configurations over to the new host, so that we have a proper baseline: sudo cat /etc/apache2/000-default.conf > /etc/apache2/myblog.conf
9 . Edit the file to match the following configurations below and replace APPLICATIONVMIP with your application VM IP:

<VirtualHost *:80>  
        DocumentRoot /var/www/myblog/
        ErrorDocument 503 /maintenance.html

        RewriteEngine on
        RewriteCond %{SERVER_NAME} !^(www\.)?your_domain\.com$
        RewriteCond %{SERVER_NAME} !^(www\.)?your_domain\.com$
        RewriteRule ^ - [F]

        ProxyRequests Off
        ProxyPass /maintenance.html !
        ProxyPass / http://APPLICATION_VM_IP:80/ 
        ProxyPassReverse / http://APPLICATION_VM_IP:80/
        ProxyRequests Off

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

10 . Now lets edit symlinks to enable the virtualhost:
cd /etc/apache2/sites-enabled sudo rm 000-default.conf sudo ln -s ../sites-available/myblog.conf myblog.conf 11 . Restart apache and we are done: sudo service apache2 restart
12 . There might be some warnings, but you can figure those out via stackoverflow.
13 . Update your DNS entry with the IP of the apache VM at port 80.

I will discuss how to setup apache load balancing in my next post.

For HTTPS configurations:

This is more complex and requires you to create a seperate VirtualHost entry in your conf file for example: <VirtualHost:443> and various other configurations.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket
Comments powered by Disqus