Welcome! Log In Create A New Profile


Re: The real difference between $host and $http_host

Maxim Dounin
August 15, 2011 06:20AM

On Mon, Aug 15, 2011 at 03:30:20AM -0400, speedfirst wrote:

> The wiki page of "$host" says $host and $host_addr are different only
> when there is no "Host" header or the "Host" header is empty. But I
> found when "Host" contains port number, $host never contains the port
> number while $http_host is equal to the value of "Host" header.
> That is, if "Host: foo:8080", then
> $http_host = foo:8080
> $host = foo
> So in this case, they are different.
> Tested in nginx 1.0.3
> I want the official confirmation of this difference.

Yes, $host variable represents host part of a Host header[1].
Moreover, in 0.8.17+ $host will be additionally lowercased. That
is, for

Host: FOO:8080

$host will be "foo" (while $http_host will be "FOO:8080" as it
just reflects the whole header).

Additionally, $host will be set to one from request uri, if
request request used absolute uri (as per RFC2616, section 5.2,
see [2]).

> And if it's
> confirmed, could you correct the illustration in wiki page?

Probably wiki as well as docs should say something like "$host
represents http host requested". The full description above is
clearly a bit too many for just a variable description.

Anyway, feel free to update wiki if you think you know what to
write there.

[1] http://tools.ietf.org/html/rfc2616#section-14.23
[2] http://tools.ietf.org/html/rfc2616#section-5.2

Maxim Dounin

nginx mailing list
Subject Author Posted

The real difference between $host and $http_host

speedfirst August 15, 2011 03:30AM

Re: The real difference between $host and $http_host

Maxim Dounin August 15, 2011 06:20AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 101
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready