Apache 2.4 virtual host ignored

xtfer picture xtfer · Sep 16, 2014 · Viewed 7.4k times · Source

I'm setting up a new web server using Ubuntu 14.0, following the instructions here for creating virtual hosts, however my single additional virtual host always loads the default site (/var/www/html).

Here is my vhost configuration (I have replaced my domain with example.com, but it is otherwise identical):

<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/example/app

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I have made NO OTHER CHANGES to the Apache 2.4 configuration which is installed in Ubuntu 14.

EDIT: I am correctly enabling sites and restarting apache after making changes to this vhost.

When I visit example.com in my browser, I get the default site. What am I doing wrong? How do I get this virtual host to load the correct directory?

EDIT: The solution is a missing "sudo" in the restart command (https://stackoverflow.com/a/23713299/225682).

Answer

pankijs picture pankijs · Sep 16, 2014

you need to restart apache we server after you edit vhost, also you need to add enable vhost. to enable:

sudo a2ensite example.conf (name of config file inside sites-available directory)

to restart server:

sudo service apache2 restart

also check out permissions for www directory, maybe apache's user can't read that directory.