Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Linode VPS that I use to host multiple sites. I run Ubuntu 10.04 and Apache 2. What I would like to do is have my live sites ( and test sites ( on the same box but have only accessible when connected to my VPS via VPN.

I have setup OpenVPN following Linode's instructions and am able to connect, but I am not sure how to setup Apache to enable this. How do I setup Apache to only allow access to test sites when connected to VPN, but allow anyone to access the live sites?

share|improve this question
up vote 1 down vote accepted

Have the virtual host definitions in Apache listen to different interfaces.

Say, the OpenVPN interface is In that case, in the virtual host definition, set VirtualHost Similarly, for, set it to listen on the primary interface with something like VirtualHost or whatever the IP of the eth0 interface is.

share|improve this answer
This makes since, but it doesn't seem to work for me. I changed the virtual host definition for to point to (which in the IP for my OpenVPN interface). I go to in Chrome and I don't get to my test site. It just says Chrome could not find I do get there if I just use the IP ( Do I need to change something in the ports.conf? Using the public IP for my live sites works just fine. – jonjon1123 Feb 11 '12 at 13:52
How are you resolving the DNS for Also, are you using NameVirtualHosts on – cjc Feb 11 '12 at 14:08
I register my domains through Namecheap so I have my DNS entries configured through them. I have configured to point back to my public IP for my VPS. I have the following lines in my ports.conf: NameVirtualHost NameVirtualHost Listen 80 – jonjon1123 Feb 11 '12 at 15:04
So, resolves to You want it to resolve to, otherwise the HTTP request will hit the public interface and not the VPN one. You're getting the "not found" error because is not a name configured on the virthost for the public interface. – cjc Feb 11 '12 at 15:21
How do I go about setting up to resolve to I can't configure that on Namecheap, can I? – jonjon1123 Feb 11 '12 at 15:31

I am assuming you're running Linux/BSD here, I believe you can do the same thing with ssh for windows though.

Another way just uses ssh ( I am using authorized keys not passwords )

VARS replace with your option

$PORT = The port you wish to set this up on
$YOURSITE = The directory your test site resides in
$YOURTESTURL = The url of your test site
$USER = the user you have setup to ssh into your server with
$YOURSERVER = the ip or url of your server

The apache config on your server

  DocumentRoot /var/www/$YOURSITE/

now in your terminal put in


Now open your web browser to $YOURTESTURL:$PORT

I use this to connect to management sites on my servers without having to expose them to the interwebs :)

hope this helps

share|improve this answer
He already has OpenVPN set up, so no need for SSH tunnels. Other than that, yes, set up the virtual hosts so that one is listening to the public interface, and the other is listening to a private one. – cjc Feb 10 '12 at 9:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.