I have two servers:

  • A (
  • B (

Both are behind firewall and only port 80 is open and forwarded to server A.

People from outside type www.mydomain.com to access my web server A.

Now I would like all of the HTTP from subdomain.mydomain.com to go to server B.


You can use mod_proxy to do this.

You set up a host entry on A for subdomain.mydomain.com to point to B, and set up B to serve this domain. You then set up a virtual host on A for subdomain.mydomain.com. This virtual host will reverse proxy / to B.

ProxyPass / http://subdomain.mydomain.com/
ProxyPassReverse / http://subdomain.mydomain.com/
  • Sorry my ignorance. I added subdomain.mydomain.com to point to hosts file and as I said the web server on B is run on Also, I added both directives to the site-availble/default file. However, it is still not working. I was wondering if someone request externally to subdomain.mydomain.com how it would get proxied to the other server. – jax Feb 22 '13 at 0:06
  • the external dns for the subdomain should be set to go to the external address for server A. Server A will then route the requests for the domain by proxying it to the backend. – drone.ah Feb 22 '13 at 13:55

To accomplish that you will need two virtual hosts and mod_proxy enabled.

In sites-enabled, you will want a file containing minimally this (and whatever other config you want):

<VirtualHost *:80>
   ServerName www.mydomain.com

   ... whatever you want to serve
<VirtualHost *:80>
   ServerName subdomain.mydomain.com
   ProxyPass / http://subdomain.mydomain.com/
   ProxyPassReverse / http://subdomain.mydomain.com/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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