# $http\_host and $host not behaving as described

**URL:** <https://www.ruby-forum.com/t/http-host-and-host-not-behaving-as-described/193199>\
**Category:** NGINX\
**Created:** [August 13, 2010, 12:41am UTC](https://www.ruby-forum.com/t/http-host-and-host-not-behaving-as-described/193199 "2010-08-13T00:41:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yang\_Z](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e274bd/32.png) [@Yang\_Z](https://www.ruby-forum.com/u/Yang_Z)\
**Post date:** [August 13, 2010, 12:41am UTC](https://www.ruby-forum.com/t/http-host-and-host-not-behaving-as-described/193199/1 "2010-08-13T00:41:36Z")

</div>

> From [Module ngx\_http\_core\_module](http://wiki.nginx.org/NginxHttpCoreModule#.24host:)

“”"  
$host

This variable is equal to line Host in the header of request or name  
of the server processing the request if the Host header is not  
available.

This variable may have a different value from $http\_host when the Host  
input header is absent or has an empty value.

$http\_HEADER  
The value of the HTTP header HEADER when converted to lowercase and  
with ‘dashes’ converted to ‘underscores’, e.g. $http\_user\_agent,  
$http\_referer…;  
“”"

When I log $host and $http\_host, I see different things, yet the Host  
HTTP header is set and non-empty.

I’m running an HTTP server on port 80 and I’m logging:

log\_format dummy ‘$host $http\_host’;  
access\_log\>-/tmp/dummy dummy;

When I browse to [http://localhost:8989/](http://localhost:8989/) where I have a proxy  
forwarding 8989 to 80 (e.g. 2 nc’s piped together, socat, or ssh  
tunneling), I see this in the log:

$ tail -f /tmp/dummy  
localhost localhost:8989

Yet if I intercept the HTTP request headers, I see:

GET / HTTP/1.1  
Host: localhost:8989  
Connection: keep-alive  
User-Agent: Mozilla/5.0 (X11; U; Linux x86\_64; en-US)  
AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.99 Safari/533.4  
Cache-Control: max-age=0  
Accept:  
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,_/_;q=0.5  
Accept-Encoding: gzip,deflate,sdch  
Accept-Language: en-US,en;q=0.8  
Accept-Charset: ISO-8859-1,utf-8;q=0.7,\*;q=0.3

## Host is set and non-empty. Anybody know what’s going on? Does the wiki need to be updated? I’m using nginx 0.7.65 (from Jeff W.'s PPA). Thanks in advance.

Yang Z.

> **[@yaaang's Garden](http://yz.mit.edu/)**
>
> Thoughts on code, no-code, and design.
