Virtual Host Setup Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I am conducting some setup tests and have come to a point where I could use some help.

Tests are using Apache version 2.2.31 for Windows. OS is Windows 7 Ultimate but I have seen the same exact behavior on Windows Server 2008 R2.

I have setup some virtual hosts and they don't seem to work as expected. So, the first setup goes like this (only the relevant parts):

Code:
Listen 192.168.1.12:80

NameVirtualHost 192.168.1.12:80

<VirtualHost 192.168.1.12:80>
    DocumentRoot "/Apache22/htdocs"
    ServerName serverone.tld
    ErrorLog "/Apache22/logs/serverone-error.log"
    CustomLog "/Apache22/logs/serverone-access.log" combined
</VirtualHost>

<VirtualHost 192.168.1.12:80>
    DocumentRoot "/Apache22/htdocs" 
    ServerName 192.168.1.12
    ErrorLog "/Apache22/logs/192.168.1.12-error.log"
    CustomLog "/Apache22/logs/192.168.1.12-access.log" combined
</VirtualHost>


Using my browser I have made the following requests:

http://serverone.tld
http://192.168.1.12


Both requests are logged under the first virtual host log file (serverone.access.log).
I would expect that the requests would be logged on different files (serverone-access.log and 192.168.1.12-access.log).

I have checked both requests and the Host: is different. On the first request it's Host: serverone.tld and on the second request it's Host: 192.168.1.12

My log files is using the following format:

Code:
LogFormat "Host:%{Host}i|CServerName:%v| %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined


And here is the serverone-access.log content:

Code:
Host:serverone.tld|CServerName:serverone.tld| 192.168.1.12 - - [13/Feb/2016:11:27:23 +0000] "GET / HTTP/1.1" 304 -
Host:192.168.1.12|CServerName:serverone.tld| 192.168.1.12 - - [13/Feb/2016:11:28:22 +0000] "GET / HTTP/1.1" 304 -


So, Apache does see different request Host: for each one of the requests.

I have read the documentation available at

https://httpd.apache.org/docs/2.2/en/vhosts/name-based.html

and the important information seems to be the following:

Quote:
...when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.


So, the question is, why does Apache place both requests under the same Virtual Host when, on a scenario using Virtual Hosts under the NameVirtualHost paradigm it should look at the Host: to decide what Virtual Host to use.

Any help is welcome.

...

Oh, and by the way, the following works flawlessly:

Code:
Listen 80

NameVirtualHost *:80

<VirtualHost *:80>
    DocumentRoot "/Apache22/htdocs"
    ServerName serverone.tld
    ErrorLog "/Apache22/logs/serverone-error.log"
    CustomLog "/Apache22/logs/serverone-access.log" combined
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/Apache22/htdocs"
    ServerName 192.168.1.12
    ErrorLog "/Apache22/logs/192.168.1.12-error.log"
    CustomLog "/Apache22/logs/192.168.1.12-access.log" combined
</VirtualHost>


The above, for the previously described requests, produce two distinct log files:

serverone-access.log and 192.168.1.12-access.log

and as expected, they respectively contain:

Code:
Host:serverone.tld|CServerName:serverone.tld| 192.168.1.12 - - [13/Feb/2016:11:37:48 +0000] "GET / HTTP/1.1" 304 -


and

Code:
Host:192.168.1.12|CServerName:192.168.1.12| 192.168.1.12 - - [13/Feb/2016:11:37:38 +0000] "GET / HTTP/1.1" 304 -


Of course, on this last setup that works, I am telling Apache to ignore the IPs and make decisions based exclusively on the ServerName.

Anyway, can anyone please let me know, considering the above configurations, why the different behavior.

Thank you.

John

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux