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

I have big problems trying to figure this out so please help me out.

I have several virutal hosts configured and using the Debian default way of configuring vhosts.

2 folders

  • sites-available
  • sites-enabled

and some files are symlinked to sites-enabled using ln -s ... and in this step I rename the files to have a weight, 200-... 300-... to have priority.

When I try to configure a bunch of vhosts:

<VirtualHost test.host.priv:80>
  ServerName test.host.priv
  DocumentRoot "/htdocs/Private/web/production/somedomain/web"
</VirtualHost>

<VirtualHost host.com:80>
  ServerName host.com
  ServerAlias www.host.com
  DocumentRoot "/htdocs/Private/web/production/somedomain/web"
</VirtualHost>

Now I have several of these, and I have some *:80 as well. But How do I make sure that these only listen to the server name I have specified? Because apache start using these as wildcard etc. Loke every domain in this case is defaulting back to the test.host.priv if it havn't been configured in a highter priority file. I dont want that, I've tried using *:80, test.host.priv:80 and it just doesn't care, it still defaults to this, so any subdomain that isn't specified goes here.

Any advice would be great!

/Marcus

share|improve this question

1 Answer 1

Apache matches VHosts by ServerName and ServerAlias when NameVirtualHost is active on a specific Listener, I guess that's what you are missing here.

When using Debian you will have a ports.conf with a default of Listen 80 which means listen on port 80 on all available interfaces. Then you can use NameVirtualHost *:80 and write your hosts like:

<VirtualHost *:80>
  ServerName test.host.priv
  DocumentRoot "/htdocs/Private/web/production/somedomain/web"
</VirtualHost>

<VirtualHost *:80>
  ServerName host.com
  ServerAlias www.host.com
  DocumentRoot "/htdocs/Private/web/production/somedomain/web"
</VirtualHost>

You can alter that as you like, just the <VirtualHost [something]:[someport]> needs a "matching" NameVirtualHost [something]:[someport] before.

See http://httpd.apache.org/docs/2.2/mod/core.html#NameVirtualHost for details.

share|improve this answer

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.