Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 youremail@domain.com
 DocumentRoot /var/www/intranet/public_html
 ServerName employees.nationalpurchasingpartners.com
 ServerAlias employees.nationalpurchasingpartners.com
</VirtualHost>

<VirtualHost *:80>
 ServerAdmin youremail@domain.com
 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
share|improve this question
    
have you restarted apache since making changes to httpd-vhosts.conf? –  jayhendren Apr 3 '14 at 21:46
    
Also Apache has been restarted multiple times –  6paq Apr 3 '14 at 21:48
    
I'm not very familiar with Varnish but it's possible that it is changing your requests while routing them to the backend Apache server. –  Ladadadada Apr 4 '14 at 0:42
    
I have disabled varnish and no such luck still –  6paq Apr 4 '14 at 3:23
    
Needed to add the domains to the /etc/hosts file, restart Apache and everything was fine. Thanks for everyones help. If someone wants to paste that in as an answer I will accept it and move on. Thanks! –  6paq Apr 4 '14 at 5:17

2 Answers 2

up vote 1 down vote accepted

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 youremail@domain.com
 DocumentRoot /var/www/intranet/public_html
 ServerName employees.nationalpurchasingpartners.com
</VirtualHost>

<VirtualHost procurementnews.com:80>
 ServerAdmin youremail@domain.com 
 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.

share|improve this answer

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 youremail@domain.com
 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 youremail@domain.com
 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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