Apache proxy vhost to another machine or service
<- Back To BlogPublished: 26/07/2013 UTC
Updated: 26/07/2013 UTC
Recently I wanted to host some sites/services on my VPS but I didn't have the space. A solution to this that I found was to use the OpenVPN connection I have setup on my VPS and Apaches mod_proxy. Together, these services give me the ability to host larger applications and I can hide the real address (such as my home IP Address). Note: These are not critical/major websites as this connection would not be very reliable. I have found the speed to be quite decent, I would have thought it would be very slow but I have found it to be about as fast as a normal website.How it works.
I have a VirtualHost setup of my VPS to catch hosts like "something.example.com". This gets picked up and forward 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, it will run the default!) The machine at "10.0.0.120" will run the site like normal.
Enable Apache modules
Note: This may not be a full 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 vhost with the same ServerName name as above (without the proxy or redirect code).
Credits/Sources
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 © 2025 Jeremy Sells - See Site Terms/Disclaimer