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.

I seem to be having a small problem with setting up a subdomain in apache under CentOS.

I have the following:

NameVirtualHost *:80

<VirtualHost *>
  ServerName www.domain.co.uk
  ServerAlias domain.co.uk dev.domain.co.uk
   DocumentRoot "/var/www/html/domain/web"
   DirectoryIndex index.php
   Alias /sf /var/www/html/symfony14/web/sf

 <Directory "/var/www/html/domain/web">
   AllowOverride All
   Allow from All
 </Directory>
</VirtualHost>

<Directory "/var/www/html/symfony14/web/sf">
 AllowOverride All
 Allow from All
</Directory>
<VirtualHost *>
  ServerName test.domain.co.uk
  DocumentRoot "/var/www/html/domain_test/web"
  DirectoryIndex index.php
  Alias /sf /var/www/html/symfony14/web/sf

  <Directory "/var/www/html/domain_test/web">
   AllowOverride All
   Allow from All
  </Directory>
</VirtualHost>

So going to www.domain.co.uk and domain.co.uk display the contents from /var/www/html/domain, but going to test.domain.co.uk also displays the same folder contents.

Is this because of the ServerAlias ?

Thanks

UPDATED:

Added missing directive NameVirtualHost *:80

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Try putting NameVirtualHost *:80 as first line in your config file.

You can configure sub-domain by name based virtual host entries in httpd.conf. To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive.

For more information refer Subdomain Configuration.

share|improve this answer
    
I have added that, but the sudomain is still pointing at the main domains web folder. –  terrid25 Nov 25 '11 at 14:15
    
That seemed to work. I removed the <Directory></Directory> part in between the two vhosts as well. All seems to be working now! –  terrid25 Nov 25 '11 at 14:33

Well they should be showing the same content since the DocumentRoot is the same.

I suppose for the test domain it should have been DocumentRoot "/var/www/html/domain_test/web" instead of DocumentRoot "/var/www/html/domain/web"

share|improve this answer
    
I have updated the vhost, but the problem is still happening. Do subdomains need to be before the full domain? –  terrid25 Nov 25 '11 at 9:34
    
No, the order of the directives plays no role at all. Did you restart Apache after the configuration changes? –  thanosk Nov 25 '11 at 9:42
    
Yes I did. But this hasn't changed anything. –  terrid25 Nov 25 '11 at 9:44
    
Something else then is messing up. Is that the whole of your .conf file? Do you have enabled Named virtual hosts? Upload the whole of your conf file and not just this part –  thanosk Nov 25 '11 at 9:48

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.