2013-03-14 16:25:54 8 Comments
In Nginx, what's the difference between variables $host
and $http_host
.
Related Questions
Sponsored Content
14 Answered Questions
[SOLVED] 403 Forbidden vs 401 Unauthorized HTTP responses
- 2010-07-21 07:21:58
- VirtuosiMedia
- 803104 View
- 2141 Score
- 14 Answer
- Tags: http-headers http-status-code-403 http-status-codes http-status-code-401 http-response-codes
14 Answered Questions
[SOLVED] Difference between <context:annotation-config> vs <context:component-scan>
- 2011-09-14 10:28:33
- user938214097
- 301564 View
- 634 Score
- 14 Answer
- Tags: java spring configuration annotations spring-3
5 Answered Questions
[SOLVED] Nginx -- static file serving confusion with root & alias
- 2012-05-17 08:03:01
- treecoder
- 180465 View
- 352 Score
- 5 Answer
- Tags: nginx
9 Answered Questions
[SOLVED] What's the difference between Cache-Control: max-age=0 and no-cache?
- 2009-06-26 01:34:40
- rubyruy
- 368837 View
- 562 Score
- 9 Answer
- Tags: http caching http-headers
15 Answered Questions
[SOLVED] Nginx 403 error: directory index of [folder] is forbidden
- 2013-10-10 01:00:28
- Ryan
- 326065 View
- 133 Score
- 15 Answer
- Tags: configuration nginx http-status-code-403 domain-name
11 Answered Questions
4 Answered Questions
[SOLVED] Why does Unicorn need to be deployed together with Nginx?
- 2012-01-05 09:00:55
- loganathan
- 30915 View
- 131 Score
- 4 Answer
- Tags: ruby-on-rails nginx webserver unicorn
1 Answered Questions
3 Answered Questions
[SOLVED] Proper MIME media type for PDF files
- 2008-11-23 06:49:08
- friedo
- 728853 View
- 1162 Score
- 3 Answer
- Tags: pdf http-headers content-type mime
1 comments
@glarrain 2013-03-14 16:25:54
$host
is a variable of the Core module.$http_host
is also a variable of the same module but you won't find it with that name because it is defined generically as$http_HEADER
(ref).Summarizing:
$http_host
equals always theHTTP_HOST
request header.$host
equals$http_host
, lowercase and without the port number (if present), except whenHTTP_HOST
is absent or is an empty value. In that case,$host
equals the value of theserver_name
directive of the server which processed the request.@Jonathan Vanasco 2013-03-14 16:36:38
$host is specifically the first
server_name
that is defined in the current server block. if you have multipleserver_name
s, only the first one will appear.@glarrain 2013-03-14 16:41:20
True. In fact, it is quite typical to define: server_name example.com www.example.com;
@Jonathan Vanasco 2013-03-14 17:09:35
you can have multiple
server_name
directives too. if you happen to have a regex in the first one, that becomes the$host
, and all sorts of ugly stuff can happen during rewrite rules.@CMCDragonkai 2014-03-13 20:03:06
Does the
$server_name
variable equal theserver_name
directive's value or the actual server name that was selected if there were multipleserver_name
directives?