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).
6 years too late but maybe this will help someone. When debugging issues like this, first check that apache can see your virtualhost configuration: apachectl -S
You should see your virtualhost configuration in the output:
*:80 example.com (/etc/httpd/conf.d/example.com.conf:2)
If you cannot see it, maybe the config file path is not included into the main configuration file or the file itself is missing a .conf extension.
If you see your VirtualHost in the output but you're still getting the default VirtualHost instead, check the global ServerName
directive in the main configuration file. It should NOT match your VirtualHost ServerName.
Beware - if your global ServerName is not set, apache will obtain one using rDNS. So if your IP address' reverse DNS record matches example.com (same as your VirtualHost), your VirtualHost might be ignored. I believe this is a very common source of problems and I haven't found this on the forums yet. Check your IP's rDNS record with host
command if you face this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With