# The real difference between $host and $http\_host

**URL:** <https://www.ruby-forum.com/t/the-real-difference-between-host-and-http-host/210702>\
**Category:** NGINX\
**Created:** [August 15, 2011, 9:30am UTC](https://www.ruby-forum.com/t/the-real-difference-between-host-and-http-host/210702 "2011-08-15T09:30:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 15, 2011, 9:30am UTC](https://www.ruby-forum.com/t/the-real-difference-between-host-and-http-host/210702/1 "2011-08-15T09:30:55Z")

</div>

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. And if it’s  
confirmed, could you correct the illustration in wiki page?

Thanks.

Posted at Nginx Forum:

> **[The real difference between $host and $http\_host](https://forum.nginx.org/read.php?2,213799,213799#msg-213799)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![speedfirst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e19adc/32.png) [@speedfirst](https://www.ruby-forum.com/u/speedfirst)\
**Post date:** [August 15, 2011, 12:19pm UTC](https://www.ruby-forum.com/t/the-real-difference-between-host-and-http-host/210702/2 "2011-08-15T12:19:50Z")

</div>

Hello!

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

> 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] [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-14.23)  
[2] [RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-5.2)

Maxim D.
