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.

Okay so I'm running apache 2 with a couple of virtual hosts and 2 of those are running on the same domain. Now my problem is that one of those is suppose to run on a sub domain (dev.domain.com) and the other on everything else but I can't get that to work.

I've got 2 files in sites-available ( dev.domain.com and domain.com ) and both are enabled with symlinks in sites-enabled.

This is what I've got inside the files

dev.domain.com

<VirtualHost *:80>
 ServerName dev.domain.com
 ServerAlias development.domain.com

 DocumentRoot /home/myusername/public_www/dev.domain.com
 <Directory /home/myusername/public_www/dev.domain.com/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride All
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/access.log combined
</VirtualHost>

domain.com

<VirtualHost *:80>
 ServerName domain.com
 ServerAlias *.domain.com *.domain.info

    <IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} !^domain\.com$ [NC] 
  RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
 </IfModule>

 DocumentRoot /home/myusername/public_www/domain.com
 <Directory /home/myusername/public_www/domain.com/>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
 </Directory>

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
  AllowOverride All
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
 </Directory>

 ErrorLog /var/log/apache2/error.log

 # Possible values include: debug, info, notice, warn, error, crit,
 # alert, emerg.
 LogLevel warn

 CustomLog /var/log/apache2/access.log combined
</VirtualHost>

So does anyone know what's wrong with my config? I would highly appreciate the help, I've been trying with this forever now with no success.

Note: My actual domain starts with hu so I though dev.h.... would be loaded before the h.... file.

share|improve this question
    
What are you expecting to happen, and what is actually happening? –  James Lawrie Nov 13 '10 at 21:50
    
This is what happens: When I enter dev.domain.com into the browser I get redirected to domain.com which means that I'm entering the domain.com virtualhost since the dev.domain.com one doesn't have any rewrite rules. This is what I expect to happen: When I enter dev.domain.com I want to enter a site which displays the content of path/public_www/dev.domain.com/ and if I enter anything else .domain.com or just domain.com I should enter the other site. –  Hultner Nov 13 '10 at 22:32

1 Answer 1

up vote 2 down vote accepted

ServerAlias *.domain.com *.domain.info means that definition will be used for all hosts in domain.com, overiding you dev.domain.com definition.

Do you really need a wildcard there? Note that unless you're also using wildcards in your DNS entries, there is no point, and you should just create aliases for the DNS entries that actually exist.

If you really need to use the wildcard, you'll need to drop the dev.domain.com vhost, and instead use rewrite rules in the domain.com vhost to map http://dev.domain.com to e.g. http://www.domain.com/dev

share|improve this answer
    
Well I wanted to use my domain.com site as fallback for all invalid subdomains, today if I write www.domain.com, ww.domain.com, wwww.domain.com, vvv.domain.com,etc I get redirected to domain.com. And I have pointed the entire domain with all subdomains in the dns entries to my server. Is there some other way to offer a fallback site for unused subdomains? –  Hultner Nov 13 '10 at 23:08
    
Woah this is really weird. I chagned the alias to www. instead of wildcard then I tried removing domain.com while testing with a2dissite domain.com then ran apache2 reload and everything worked like I wanted. EVERYTHING worked, even easfwe.domain.com redirecting to domain.com and domain.com still worked, so I though something had to gone wrong since the site were disabled so I ls'ed sites-available and there were no symlink there for domain.com. I reenabled domain.com and reloaded, oddly everything still works as I want it. Can anyone explain this. I checked there's no duplicate entries. –  Hultner Nov 13 '10 at 23:27
    
It's your DNS. You have a DNS CNAME wildcard that is redirecting foo.domain.com to www.domain.com. Which is exactly the right way to achieve what you want. –  Jeff Leyser Nov 13 '10 at 23:32

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.