1

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?

0

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.

0
  • you should set a different name for "default"

ServerName notwww.mydomain.com

  • also you can set all NameVirtualHost and VirtualHost to *:80 just for uniformity of the config

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.