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.

On my Vserver Id like to configure a subdomain. So I have the following entries in my apache vhost config. I want to have my site app1.example.com to run as own site, so that pages and files have the domain e.g. app1.example.com/photo.jpg or app1.example.com/blog/.

<VirtualHost *:80>
  DocumentRoot /var/www/app1
  ServerName app1.example.com
<VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/example
  ServerName example.com
<VirtualHost>

<VirtualHost *:80>
  DocumentRoot /var/www/wildcard
  ServerName other.example.com
  ServerAlias *.example.com
<VirtualHost>

But WHY do I need a DNS like this additionally? Dont I set this already in my vhost config?

Host        Type    Destination
app1        A       78.xx.xx.xx (my IP)
*           A       78.xx.xx.xx

Or do I need to point the destination to a directory like this: app1.example.com Thx for advise!

share|improve this question

2 Answers 2

If you have a wildcard record pointing to the IP of your subdomain you won't need the more specific app1 A record, the wildcard will take care of that. The user's browser sends:

Host: app1.example.com

When it makes a request for that domain, that's how Apache knows which domain the client wants. The wildcard record will tell the browser to send that request to your server.

share|improve this answer

Hmm, I think that perhaps part of the problem is the usage of '=' in setting DocumentRoot. Unless that is some alternative syntax that is rarely used the apache documentation appears to recommend using something like 'DocumentRoot /foo/bar' where /foo/bar is the document root you want. See http://httpd.apache.org/docs/2.1/mod/core.html#documentroot . With regards to your dns issue, the user's browser will send the host header, which if you have the NameVirtualHosts directive set prooerly, will cause the VirtualHost directive with the matching ServerName or ServerAlias to be used. You can configure your DNS server with either a wildcard '*' entry or specific entries or both - the browser will still send the appropriate hosts header.

share|improve this answer
    
yes the = is a syntax error :) –  DannyRe Feb 7 '12 at 10:56
    
It's all good, mate. Apache config directives do have some interesting syntax. –  Justin Lynn Feb 7 '12 at 10:58

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.