Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Our server is running Apache on port 9000 (because IIS is at 80) and we have the following configuration (vhosts.conf) to access our sites:

NameVirtualHost *:9000
UseCanonicalName Off

<VirtualHost *:9000>
    ServerAlias %1.ourserver
    VirtualDocumentRoot D:/oursites/%1
    VirtualScriptAlias D:/oursites/%1
</VirtualHost>

So we can open the browser and access by http://someclient.ourserver:9000/. So far so good.

Now we are installing a new server, where Apache will run on port 80, but we need that one specific site to have the VirtualDocumentRoot to a different drive/directory. We tried something like this (with no success):

NameVirtualHost *:80
UseCanonicalName Off

<VirtualHost specificsite.ourdomain.com:80>
    ServerAlias specificsite.ourdomain.com
    VirtualDocumentRoot C:/specificsite
    VirtualScriptAlias C:/specificsite
</VirtualHost>

<VirtualHost *:80>
    ServerAlias %1.ourserver
    VirtualDocumentRoot D:/oursites/%1
    VirtualScriptAlias D:/oursites/%1
</VirtualHost>

When we test, the result is that, accessing http://specificsite.ourdomain.com/ on browser, Apache tries to "redirect" to D:/oursites/specificsite, which is not correct.

Accessing http://someclient.ourserver/ Apache redirects correctly to D:/oursites/someclient.

So what am I missing? Looks like I am forgetting a little detail that is resulting in all requests falling at the second VirtualHost.

More info:

  • Running Xampp 1.7.7 on
  • Windows Server 2008 R2 with
  • Two entries on DNS management: one for the *.ourserver and another for the specificsite.ourdomain.com;
  • The reason of using specificsite.ourdomain.com is that our clients can access this specific site that is hosted on our server.

Thanks in advance for any help!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Two issues:

  1. ServerAlias doesn't support the same variables as VirtualDocumentRoot - that vhost's alias is set to literally %1.ourserver.
  2. Your declaration of the new vhost doesn't match the NameVirtualHost directive, so it's not being checked when a request comes in on that host/port combination. It's using DNS to find the address to bind to, so the fact that it didn't knock the dynamic vhost offline means that your server's probably behind a NAT.

Try this:

NameVirtualHost *:80

# Put this one's configuration first, so that it's the default.
<VirtualHost *:80>
    # Add a ServerName directive so that it doesn't guess - it can be anything
    ServerName dynamic.filler.name
    ServerAlias *.ourserver
    VirtualDocumentRoot D:/oursites/%1
    VirtualScriptAlias D:/oursites/%1
</VirtualHost>

<VirtualHost *:80>
    ServerName specificsite.ourdomain.com
    VirtualDocumentRoot C:/specificsite
    VirtualScriptAlias C:/specificsite
</VirtualHost>
share|improve this answer
    
I will test this configuration as soon as possible (maybe tonight (in 2 hours) or tomorrow at noon because I can't put the new server in the network with everybody using the old one), but it looks good. –  Rodrigo Saling May 17 '12 at 20:17
    
Can I buy you a beer? Your code worked perfectly! –  Rodrigo Saling May 18 '12 at 16:29
    
Glad to hear it! :) –  Shane Madden May 18 '12 at 16:34
add comment

Your Answer

 
discard

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.