3

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
Zypher
  • 36,995
  • 5
  • 52
  • 95
6paq
  • 33
  • 1
  • 6
  • have you restarted apache since making changes to `httpd-vhosts.conf`? – jayhendren Apr 03 '14 at 21:46
  • Also Apache has been restarted multiple times – 6paq Apr 03 '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 04 '14 at 00:42
  • I have disabled varnish and no such luck still – 6paq Apr 04 '14 at 03: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 04 '14 at 05:17
  • Just for future reference, adding: `ErrorLog "logs/vhostname-error_log"` `CustomLog "logs/vhostname-access_log" common` And tailing your logs will show you which vhost is getting hit. Will make your debugging easier. – Eduardo Romero Aug 19 '14 at 00:00

2 Answers2

3

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.

Itai Ganot
  • 10,424
  • 27
  • 88
  • 143
1

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.

Aaron
  • 2,809
  • 2
  • 11
  • 29