# An error with the docs of $host

**URL:** <https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891>\
**Category:** NGINX\
**Created:** [November 30, 2012, 4:18am UTC](https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891 "2012-11-30T04:18:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 30, 2012, 4:18am UTC](https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891/1 "2012-11-30T04:18:45Z")

</div>

Hi,

In the docs of $host at  
[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#variables), it  
says:

$host  
Host request header field, or the server name matching a request if this  
field is not present

It’s not right with the host header like: [www.example.com:1234](http://www.example.com:1234). The  
$host  
variable always strips the port.

---

<div class="post-metadata">

**Author:** ![yaoweibin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoweibin](https://www.ruby-forum.com/u/yaoweibin)\
**Post date:** [November 30, 2012, 8:08am UTC](https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891/2 "2012-11-30T08:08:59Z")

</div>

On Fri, Nov 30, 2012 at 11:18:15AM +0800, 姚伟斌 wrote:

> variable always strips the port.  
> How’s this instead?

# %%% Index: xml/en/docs/http/ngx\_http\_core\_module.xml

— xml/en/docs/http/ngx\_http\_core\_module.xml (revision 775)  
+++ xml/en/docs/http/ngx\_http\_core\_module.xml (working copy)  
@@ -2754,8 +2754,10 @@

$host  
  
-Host request header field,  
-or the server name matching a request if this field is not present  
+in this order of precedence:  
+host from the request line, or  
+host from the Host request header field,  
+or the server name matching a request

$hostname  
%%%

---

<div class="post-metadata">

**Author:** ![yaoweibin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoweibin](https://www.ruby-forum.com/u/yaoweibin)\
**Post date:** [November 30, 2012, 11:06am UTC](https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891/3 "2012-11-30T11:06:02Z")

</div>

Hi Ruslan,

Most of the content is fine for me. Could you add a line like that the  
variable $host exclude the port explicitly? I know the host should mean  
the  
server name, not include the port. It just confuses me when I use the  
directive like this:

proxy\_set\_header Host $host;

But the port is missing. Maybe I shoud use the $http\_host instead.

Thanks.

2012/11/30 Ruslan E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![yaoweibin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/e9bcb4/32.png) [@yaoweibin](https://www.ruby-forum.com/u/yaoweibin)\
**Post date:** [November 30, 2012, 11:37am UTC](https://www.ruby-forum.com/t/an-error-with-the-docs-of-host/224891/4 "2012-11-30T11:37:00Z")

</div>

On Fri, Nov 30, 2012 at 06:05:42PM +0800, 姚伟斌 wrote:

> Hi Ruslan,
> 
> Most of the content is fine for me. Could you add a line like that the  
> variable $host exclude the port explicitly? I know the host should mean the  
> server name, not include the port.

: GET [http://example.com:12345/uri](http://example.com:12345/uri) HTTP/1.1  
: Host: example.net:54321

results in $host being set to “[example.com](http://example.com)”, while

: GET /uri HTTP/1.1  
: Host: example.net:54321

results in $host being set to “[example.net](http://example.net)”, as required by  
[RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1 | RFC Editor](http://tools.ietf.org/html/rfc2616#section-5.2)

If I say about port stripping in case #2, should I say about  
requestURI stripping to extract the “host” part? I’d like  
to avoid detailing it too much, and in my opinion “host from  
the …” fits both cases.

> It just confuses me when I use the  
> directive like this:
> 
> proxy\_set\_header Host $host;
> 
> But the port is missing.

That is understood. The previous description was incorrect.  
Thanks for noticing.

> Maybe I shoud use the $http\_host instead.

It depends on what you need.

> 2012/11/30 Ruslan E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> […]
