$http_host and $host not behaving as described

Yang Zhang yanghatespam at gmail.com
Fri Aug 13 02:40:38 MSD 2010


>From 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/ 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 Waugh's PPA).
Thanks in advance.
--
Yang Zhang
http://yz.mit.edu/



More information about the nginx mailing list