0

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!

1 Answers1

1

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>
Shane Madden
  • 114,520
  • 13
  • 181
  • 251