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 am running an Ubuntu server with apache2 on my VPS server. I've set up a virtual host that works fine.

/etc/hosts
127.0.0.1    localhost.localdomain    localhost

/etc/apache2/ports.conf
NameVirtualHost 93.125.30.25:80
Listen 80

/etc/apache2/sites-enabled/website.com
<VirtualHost 93.125.30.25:80>
        ServerAdmin webmaster@localhost
        ServerName website.com
        ServerAlias www.website.com
        DocumentRoot /var/www/website.com/web
</VirtualHost>

Now, I would like to have a sub.website.com subdomain with a different document root, so I add one more virtual host:

/etc/apache2/sites-enabled/sub.website.com
<VirtualHost 93.125.30.25:80>
        ServerAdmin webmaster@localhost
        ServerName sub.website.com
        DocumentRoot /var/www/sub.website.com/web
</VirtualHost>

But sub.website.com doesn't work (Server not found in browsers). Any ideas? Do I need a DNS server for subdomains to work?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

You certainly need a DNS entry (either an A or CNAME record) for the subdomain if you want the name to be resolvable. How you go about this depends where you have your domain registered.

share|improve this answer
    
Technically it's not where you have your domain registered but where you have your Name Server pointing to. –  hfranco Feb 24 '11 at 21:19
    
Indeed, I had to ask the hosting company to do this and it works straight away. I wonder if I could do it by setting up DNS server myself on my VPS server? –  Dziamid Feb 24 '11 at 22:14
    
@hfranco: Aye, but for most people the two are the same. @Dziamid: You could run your own DNS, I do for my domains, but I would guess that doing it right is more hassle than it is worth to you. Most registrar's DNS setups and control panels allows you to configure this sort of thing yourself, so if your host does not perhaps you could consider transferring the domain? –  David Spillett Feb 24 '11 at 23:24

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.