Simple Apache reverse proxy example

Simple Apache reverse proxy example

Get Social!


Apache can be used as a reverse proxy to relay HTTP/ HTTPS requests to other machines. This is common practice and comes with two main benefits:

  • Security – Your Apache instance can be put in a DMZ and exposed to the world while the web servers can sit behind it with no access to the outside world.
  • Reduce load – You can reduce the load on the web servers with various methods such as web caching at the proxy, load balancing and deflecting traffic for invalid requests.

The interesting stuff – ProxyPass

To set up Apache as a reverse proxy server you will need to enable mod_proxy. Some other common mods you may need are below.

  • mod_proxy
  • mod_http
  • mod_headers
  • mod_html

To enable mods in Ubuntu/ Debian you need to make sure they are installed, then enabled. For example, installing and enabling mod_proxy would look like this:

apt-get install libapache2-mod-proxy-html a2enmod mod_proxy

Once these mods are enabled, we can begin editing the Apache config. The locations of these vary depending on your Linux distribution. For RHEL based distributions, this will be your httpd.conf; for Debian based, sites-available/default.

Inside your VirtualHost tag create a Location tag which matches the external path you wish to use. For this example we will use /.

<Location />
    # commands go here

Inside the Location tag add the proxy options ProxyPass and ProxyPassReverse followed by the site address which will be the target of the proxy. You will also need a couple of lines to allow access.

    Order allow,deny
    Allow from all

Outside of the location tags, towards the top of the virtual host add a few extras:

    ProxyHTMLStripComments on
    ProxyRequests off
    SetOutputFilter proxy-html
    ProxyHTMLDoctype XHTML

If you will be proxying SSL traffic, you will also need to add:

    SSLProxyEngine on

Restart apache or reload the settings for the changes to take effect:

    service apache2 reload

You will now have a working proxy – all requests sent to / will be fetched from

Example Apache reverse proxy VirtualHost

The below example shows an Apache VirtualHost which is listening on port 80. The confiiguration accepts requests on which match the hostname and proxys the requests to the backend server

<VirtualHost *:80>
    ServerAdmin [email protected]
    ProxyRequests off
    DocumentRoot /var/www
    SSLProxyEngine on
    ProxyPreserveHost On


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

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel error

    <Location />
        Order allow,deny
        Allow from all


Related posts:


R Hejc

20-Feb-2014 at 5:06 pm

Are you able to proxy Java Console (KVM for servers)? I’m getting message Connected to sevrer on port 5900, but Java never start when behind proxy…


    20-Feb-2014 at 5:27 pm

    I have not found a way to do this with Apache.


28-Apr-2014 at 3:25 pm

Thank you.
Your tip worked for me.

Ian Miell

3-Jun-2014 at 8:23 pm

I’ve long struggled with getting this working when playing with it casually until stumbling across this article, so have written this up into a ShutIt module:

To get a copy of the container:

docker pull imiell/apache_proxypass

More context:


25-Jan-2015 at 4:21 am

I am newbie to reverse proxy and i came across your articles in google when i was searching for reverse proxy. I am impressed with your work. I am having proxmox at my home. Would you please guide step by step how to setup reverse proxy for proxmox or atleast give the order of your links to follow. I followed this page but unable to install the packages.



    26-Jan-2015 at 9:59 am

    What errors are you getting?


22-Jan-2016 at 8:43 pm

I need to block one URL

but same time my main URL should work like


any idea How to do that



7-Mar-2016 at 10:38 pm


Thanks for the great tutorial!

is it possible to make the proxy preserve the original url? i can see that you set the “ProxyPreserveHost On” but the address seems to be overwritten.



10-May-2016 at 5:47 pm

if you want to use apache only as a reverse proxy, why is it neccessary to implement the line “ProxyPass“? Not only “ProxyPassReverse“?
Thanks for answer.

Phil Gardner

2-Nov-2016 at 4:09 pm

This isn’t working in Ubuntu 16.04 – Apache rejects the code and reverts the virtual host config file to the previous version. Any ideas?


    2-Nov-2016 at 6:07 pm

    What does it reject? Does the error.log give any more information?

Daniel Cunil

14-Jun-2017 at 6:04 pm

Hey, I’m trying to do the same for nginx. Get error:

[proxy:error] [pid 2158:tid 140667709277952] (111)Connection refused: AH00957: HTTPS: attempt to connect to ( failed
[proxy_http:error] [pid 2158:tid 140667709277952] [client x.x.x.x:61269] AH01114: HTTP: failed to make connection to backend:


5-Aug-2017 at 4:48 am

We have a server1 as and we have setup reverse proxy on this such that will serve contents from server2. Server2 also has apache2 and domain name configured in VirtualHost is… we want this server2 to also pass contents when is called…

I understand settings at server1 and have also done other relevant settings. However, can you please help with what settings I need to do on server2?

Many thanks


30-Sep-2017 at 5:59 pm

I need your help in configuring multi domain authentication through ldap in httpd.conf


8-Jul-2018 at 3:20 pm

i did as the above example but my apache dies?

Leave a Reply to james.coyle Cancel reply

Visit our advertisers

Quick Poll

Do you use ZFS on Linux?

Visit our advertisers