Apache Centos 6.5 Only Loading First Virtual Host

Like the question states only the first Virtual Host is loaded. If I go to the second domain then it simply directs to the first domain. I can load individual files on the second domain but I am unable get the index file to load.

NameVirtualHost *:80
<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/intranet/public_html
 ServerName employees.nationalpurchasingpartners.com
 ServerAlias employees.nationalpurchasingpartners.com
</VirtualHost>

<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/procurement/public_html
 ServerName www.procurementnews.com
 ServerAlias procurementnews.com
</VirtualHost>

I have run through the following link to no avail.

http://wiki.apache.org/httpd/CommonMisconfigurations

Adding output of curl:

HTTP/1.1 200 OK
Server: Apache
Set-Cookie: COOKIE=10.5.19.235.1396565642197130; path=/
ETag: "AAAAUSZYEDQ"
Last-Modified: Thu, 06 Mar 2014 21:50:26 GMT
Set-Cookie: referrer=; path=/
Set-Cookie: t=d9979760bb8211e39a570015c5e70b87; path=/
Set-Cookie: referrer=procurementnews.com; path=/
Vary: Accept-Encoding,User-Agent
Cartoon: aalander4
Content-Type: text/html; charset=UTF-8
Date: Thu, 03 Apr 2014 22:54:02 GMT
X-Varnish: 1862602499
Age: 0
Via: 1.1 varnish
Connection: keep-alive

Output of httpd -S

httpd -S

*:80                   is a NameVirtualHost
     default server employees.nationalpurchasingpartners.com (/etc/httpd/conf/httpd.conf:1012)
     port 80 namevhost employees.nationalpurchasingpartners.com (/etc/httpd/conf/httpd.conf:1012)
             alias employees.nationalpurchasingpartners.com
     port 80 namevhost www.procurementnews.com (/etc/httpd/conf/httpd.conf:1019)
             alias procurementnews.com

Solution 1:

If you are configuring Name-Based virtual hosts, then this is how it should be done as far as I understand:

Edit your httpd.conf like so:

NameVirtualHost *:80
<VirtualHost employees.nationalpurchasingpartners.com:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/intranet/public_html
 ServerName employees.nationalpurchasingpartners.com
</VirtualHost>

<VirtualHost procurementnews.com:80>
 ServerAdmin [email protected] 
 DocumentRoot /var/www/procurement/public_html
 ServerName www.procurementnews.com
 ServerAlias procurementnews.com *.procurementnews.com
</VirtualHost>

And then run:

# /etc/init.d/httpd restart

If you want to test it on the very same machine you'll have to update the server's /etc/hosts file and include there:

1.1.1.1 employees.nationalpurchasingpartners.com
2.2.2.2 procurementnews.com

Or make sure your DNS server has these records set.

Please update if it works or not.

Solution 2:

Does your global configuration (anything outside of a VirtualHost) contain the same ServerName? You could add a logfile definition for your global config and one for each of your virtual hosts to see what traffic is being served by each one.

Back up all of your configuration files before testing anything and always use "configtest" before attempting to apply any changes.

In httpd.conf:

CustomLog logs/default_access_log combined

And then in your VirtualHost definition, add a CustomLog entry for each:

<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/intranet/public_html
 ServerName employees.nationalpurchasingpartners.com
 ServerAlias employees.nationalpurchasingpartners.com  # this entry is redundant

    CustomLog logs/employees.nationalpurchasingpartners.com_access_log combined

</VirtualHost>

<VirtualHost *:80>
 ServerAdmin [email protected]
 DocumentRoot /var/www/procurement/public_html
 ServerName www.procurementnews.com
 ServerAlias procurementnews.com

    CustomLog logs/www.procurementnews.com_access_log combined

</VirtualHost>

I see that you have Varnish in front of your server. You should also verify that Varnish is using HTTP/1.1 to properly support Host headers. You may want to also enable logging in Varnish so you can see what is being sent back to Apache.

You could also log the "Host" header being sent to Apache by copying the LogFormat line of combined to a new entry and adding

\"%{Host}i\"

e.g.

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{Host}i\"" with_host

Then change the above Apache CustomLog entries to use "with_host" instead of "combined.

Be sure to revert your changes after testing to restore your server to normal operation.