Eric,


Thank you very much for your reply.

I have two requests:




*http://serverone.tld <http://serverone.tld>http://1
<http://127.0.0.1/>92.168.1.12*

On the first one the request header Host is:  “*Host: serverone.tld*”

And on the second one the request header Host is: “*Host: 192.168.1.12*”



Now, I have run the *httpd.exe –S* command and the result is as follows:



*Code:*

VirtualHost configuration:

192.168.1.12:80        is a NameVirtualHost

         default server serverone.tld (D:/Apache22/conf/httpd.conf:51)

         port 80 namevhost serverone.tld (D:/Apache22/conf/httpd.conf:51)

         port 80 namevhost 192.168.1.12 (D:/Apache22/conf/httpd.conf:65)



So, I have one NameVirtualHost, 192.168.1.12:80. This NVH has three
options: *default, serverone.tld and 192.168.1.12*.



The test that is failing is the one where “*Host: 192.168.1.12*”, so I will
focus on this one. It seems to me that the Apache server cannot match
the “*Host:
192.168.1.12*” with the ServerName (ServerName 192.168.1.12) and, because
of this unexpected mismatch, it’s using the *default* virtual host for
serving the request.

A simple test that confirms my suspicion involves changing the virtual host
definition order in the configuration file:



*Code:*

Listen 192.168.1.12:80

NameVirtualHost 192.168.1.12:80

<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>

<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>


Is this configuration, if one runs *httpd.exe –S*, the default server
changed (as expected).



*Code:*

VirtualHost configuration:

192.168.1.12:80        is a NameVirtualHost

         default server 192.168.1.12 (D:/Apache22/conf/httpd.conf:60)

         port 80 namevhost 192.168.1.12 (D:/Apache22/conf/httpd.conf:60)

         port 80 namevhost serverone.tld (D:/Apache22/conf/httpd.conf:67)



With the above *default* virtual hots set to *192.168.1.12*. the *http://1
<http://127.0.0.1/>**92.168.1.12* request is logged under the “correct”
virtual host. Not because it’s matched. Just because the “correct” virtual
host for the request happens to be the *default*.



Now, let’s see if I understood your answer correctly. You mention that the
Host is compared to the address/hostname in the <virtualhost> itself. So, I
believe you are saying that when the host is “*Host: 192.168.1.12*” it is
compared to <VirtualHost 192.168.1.12:80> and that being a match with the
first defined virtual host, it stops searching other virtual hosts,
completely ignoring the ServerName field.

Is my reading your answer correctly?

Thank you.



John



*From:* Eric Covener [mailto:cove...@gmail.com <cove...@gmail.com>]
*Sent:* Saturday, February 13, 2016 3:57 PM
*To:* users@httpd.apache.org
*Subject:* Re: [users@httpd] Virtual Host Setup Help





On Sat, Feb 13, 2016 at 6:43 AM, Meta Correio <meta.corr...@gmail.com>
wrote:

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.



​There is an under-ocumented, less used/understood matching step for NVH
where the Host is compared to the address/hostname in the <virtualhost>
itself. This is what messes with your test using the IP address.





-- 

Eric Covener
cove...@gmail.com

Reply via email to