Configure Name-based Virtual Hosts on Linode

apache-2.2hostingvirtualization

I'm learning to configure name-based virtual host for apache 2.

Right now, my domain http://mydomain.com points to /var/www/index.html. I want it to point to my newly created /srv/www/mydomain.com/public_html/index.html.

I currently have two files:

  • /etc/apache2/sites-available/default
  • /etc/apache2/sites-available/mydomain.com

This is what they look like:

/etc/apache2/sites-available/default

NameVirtualHost myipaddr:80

<VirtualHost myipaddr:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
## other default directives
</VirtualHost>

/etc/apache2/sites-available/mydomain.com

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

I executed a a2ensite mydomain.com and restarted apache, but http://mydomain.com still points to the default /var/www/ directory. I guess apache is not registering my /etc/apache2/sites-available/mydomain.com file?

Did I miss a step in my configuration and installation?

Best Answer

I am not sure that it is the problem, but the first thing that sticks out is that your are using an IP in your NameVirtualHost setting, and a wildcard in the for the mydomain.com. You probably should use a wildcard for the NameVirtualHost and the default virtual host.

Related Topic