2

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 (example-site.com) and test sites (test.example-site.com) on the same box but have test.example-site.com 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?

2 Answers 2

1

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

Say, the OpenVPN interface is 10.8.0.101. In that case, in the test.example.com virtual host definition, set VirtualHost 10.8.0.101:80. Similarly, for www.example.com, set it to listen on the primary interface with something like VirtualHost 192.168.1.1:80 or whatever the IP of the eth0 interface is.

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

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

<VirtualHost 127.0.0.1:$PORT>
  DocumentRoot /var/www/$YOURSITE/
  ServerName $YOURTESTURL
</VirtualHost>

now in your terminal put in

 ssh -L $PORT:127.0.0.1:$PORT $USER@$YOURSERVER

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

1
  • 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, 2012 at 9:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .