Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: VIrtual Host Setup |
|
Author |
|
jmcl
Joined: 11 Feb 2016 Posts: 10
|
Posted: Thu 11 Feb '16 23:11 Post subject: VIrtual Host Setup |
|
|
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 127.0.0.1:80
Listen 192.168.1.69:80
NameVirtualHost 127.0.0.1:80
NameVirtualHost 192.168.1.69:80
<VirtualHost 127.0.0.1:80:80>
DocumentRoot "/Apache22/htdocs"
ServerName localhost
ErrorLog "/Apache22/logs/localhost-error.log"
CustomLog "/Apache22/logs/localhost-access.log" combined
</VirtualHost>
<VirtualHost 127.0.0.1:80:80>
DocumentRoot "/Apache22/htdocs"
ServerName 127.0.0.1
ErrorLog "/Apache22/logs/127.0.0.1-error.log"
CustomLog "/Apache22/logs/127.0.0.1-access.log" combined
</VirtualHost>
<VirtualHost 192.168.1.69:80>
DocumentRoot "/Apache22/htdocs"
ServerName 192.168.1.69
ErrorLog "/Apache22/logs/192.168.1.69-error.log"
CustomLog "/Apache22/logs/192.168.1.69-access.log" combined
</VirtualHost> |
Using my browser I have made the following requests:
http://localhost
http://127.0.0.1
Both requests are logged under the first virtual host log file (localhost-access.log).
I would expect that the requests would be logged on different files (localhost-access.log and 127.0.0.1-access.log).
I have checked both requests and the Host: is different. On the first request it's Host: localhost and on the second request it's Host: 127.0.0.1.
My log files is using the following format:
Code: | LogFormat "[b]%{Host}i[/b]|%v|%V| %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined |
And here is the localhost-access.log content:
Code: | [b]localhost[/b]|localhost|localhost | 127.0.0.1 - - [11/Feb/2016:20:48:38 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36"
[b]127.0.0.1[/b]|localhost|127.0.0.1 | 127.0.0.1 - - [11/Feb/2016:20:48:43 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36" |
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 flawlessy:
Code: | Listen 80
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/Apache22/htdocs"
ServerName localhost
ErrorLog "/Apache22/logs/localhost-error.log"
CustomLog "/Apache22/logs/localhost-access.log" combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Apache22/htdocs"
ServerName 127.0.0.1
ErrorLog "/Apache22/logs/127.0.0.1-error.log"
CustomLog "/Apache22/logs/127.0.0.1-access.log" combined
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/Apache22/htdocs"
ServerName 192.168.1.69
ErrorLog "/Apache22/logs/192.168.1.69-error.log"
CustomLog "/Apache22/logs/192.168.1.69-access.log" combined
</VirtualHost> |
The above, for the previously described requests, produce two distinct log files:
localhost-access.log and 127.0.0.1-access.log
and as expected, they respectively contain:
Code: | [b]localhost[/b]|localhost|localhost | ::1 - - [11/Feb/2016:21:01:31 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36" |
and
Code: | [b]127.0.0.1[/b]|127.0.0.1|127.0.0.1 | 127.0.0.1 - - [11/Feb/2016:21:01:36 +0000] "GET / HTTP/1.1" 304 - "-" "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36" |
Of course, on this last setup that works, I am telling Apache to ignore the IPs and make decisions based exclusively on the ServerName.
So maybe the IPs are the problem... |
|
Back to top |
|
|
|
|
|
|