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'm using Ubuntu 10.04 and Apache2.2 on a Linode VPS - I'm trying to create a subdomain sub.mysite.com of mysite.com. I've added this entry to /etc/apache2/sites-enabled:

<VirtualHost *:80>
     ServerAdmin email@gmail.com
     ServerName mysite.com
     ServerAlias sub.mysite.com
     DocumentRoot /srv/www/sub.mysite.com/public_html/
     ErrorLog /srv/www/sub.mysite.com/logs/error.log
     CustomLog /srv/www/sub.mysite.com/logs/access.log combined
</VirtualHost>

and this line to /etc/hosts:

127.0.0.1       sub.mysite.com

and created a DNS zone file pointing to sub.mysite.com...

I can successfully ping sub.mysite.com but can't get index.html to load in my browser...

Any ideas?

share|improve this question
    
What does the error.log and access.log tells you? –  Rilindo Jul 4 '11 at 16:06
add comment

2 Answers

up vote 1 down vote accepted

Since you're using virtual hosts, make sure to put this subdomain container BEFORE your main virtual host container. What ever comes first trumps whatever comes after, so if your file looks like this, it won't work:

<virtualHost *:80>
 {snip}
 ServerAlias *.mysite.com
 DocumentRoot /srv/www/mysite.com/public_html/
 {snip}
</virtualHost>

<VirtualHost *:80>
 {snip}
 ServerAlias sub.mysite.com
 DocumentRoot /srv/www/sub.mysite.com/public_html/
 {snip}
</VirtualHost>

Make sense? You have to flip them, so that the 2nd VirtualHost container in my example is first. If that's not the problem, and you've already done this, then check the Apache error log (actually, that should be your first step, regardless).

Also, make sure file permissions are correct.

share|improve this answer
add comment

Be sure that you have NameVirtualHost *:80 somewhere in your configuration files. Debian adds it in default configuration in the file /etc/apache2/ports.conf (I guess that Ubuntu do the same). Then debug your vhost configuration with apache2ctl -S as root, it will give you a list of correctly configured virtual hosts. The output should be similar to this

VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   is a NameVirtualHost
         default server usually-default-hostname (/etc/apache2/sites-enabled/000-default:1)
         port 80 namevhost sub.mysite.com (/etc/apache2/sites-enabled/your-config:1)

If your vhost is not listed here that's why you can't browse it (ensure you've reloaded the apache configuration with /etc/init.d/apache2 reload before browsing).

See here for full instructions to setup vhosts in apache under Debian/Ubuntu

share|improve this answer
add comment

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.