Apache Proxy VirtualHost to Another Machine or Service

Recently, I wanted to host some sites and services on my VPS, but I did not have the storage space. The solution I found was to use the OpenVPN connection I had set up on my VPS with Apache's mod_proxy. Together, these services let me host larger applications while hiding the real address, such as my home IP address. Note: These are not critical or major websites, as this connection would not be very reliable. I have found the speed to be quite decent. I expected it to be slow, but it feels about as fast as a normal website.

How it works

I have a VirtualHost set up on my VPS to catch hosts such as something.example.com. This gets picked up and forwarded to a machine such as 10.0.0.120. The machine at 10.0.0.120 also has a VirtualHost with the same domain set. If it does not match, Apache will run the default host. The machine at 10.0.0.120 then runs the site as normal.

Enable Apache modules

Note: This may not be a complete list.

# a2enmod proxy_http
# a2enmod header

Example VPS vhost

<IfModule mod_ssl.c>
    <VirtualHost *:80>
        ServerName something.example.com
    
        # Uncomment if you want redirect from HTTP to HTTPS
        RewriteEngine on
        RewriteCond %{SERVER_PORT} ^80$
        RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]
        CustomLog /var/log/apache2/something-access.log combined
        ErrorLog /var/log/apache2/something-error.log
    </VirtualHost>
    
    <VirtualHost *:443>
        ServerName something.example.com
    
        # Uncomment the following line to prevent redirects to http on https only vhosts
        RequestHeader set X-Forwarded-Proto "https"
        ProxyPass / http://10.0.0.120/
        ProxyPassReverse / http://10.0.0.120/
        ProxyPreserveHost On
        SSLEngine on
    
        # ADD SSL cert here etc
        CustomLog /var/log/apache2/something-access.log combined
        ErrorLog /var/log/apache2/something-error.log
    </VirtualHost>
</IfModule>

Example receiver vhost

This is a typical VirtualHost with the same ServerName as above, without the proxy or redirect code.

Credits/Sources

GitLab Apache recipe

Published: 26/07/2013 UTC

Updated: 18/06/2026 UTC

<- Back To Blog

The opinions expressed on this website are my own and do not necessarily reflect the views of my employer. The posts on this website are provided "as is" with no warranties and confer no rights

Copyright © 2026 Jeremy Sells - See Site Terms/Disclaimer