Running CentOS 6, Apache.
I have the following in my httpd.conf:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName domain1.example
ServerAlias www.domain1.example
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/domain2
ServerName domain2.example
ServerAlias www.domain2.example
</VirtualHost>
Whenever I visit domain2.example
(or www.domain2.example
), I am shown domain1.example
.
EDIT: More info from httpd.conf
Listen 80
#NameVirtualHost *:80
Things I have checked:
- Apache has been restarted
- DNS for
domain1.example
anddomain2.example
point to same IP
What am I missing?
SOLUTION:
As Patrick points out, in Apache 2.2, NameVirtualHost
is required when using multiple VirtualHost
s. The solution here was to uncomment the line in httpd.conf
:
#NameVirtualHost *:80
to:
NameVirtualHost *:80