# IPv6 addresses for host name are incorrectly trimmed by nginx

**URL:** <https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761>\
**Category:** NGINX\
**Created:** [November 28, 2010, 8:20pm UTC](https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761 "2010-11-28T20:20:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 28, 2010, 8:20pm UTC](https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761/1 "2010-11-28T20:20:43Z")

</div>

I’m trying to test IPv6 on a couple of sites and I seem to have  
encountered  
a bug with nginx.

I have 2 backend servers behind a proxy, all servers run nginx 0.8.53.

If I enter the IPv6 address into the browser, the address is trimmed  
when it  
reaches the backend server.

Here is an example using PHP:

Direct request to backend server (works):

http://[2a02:40:40:7::3]/test.php  
$\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7::3]

Via proxy:

http://[2a02:40:40:7::7]/test.php  
$\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7:

It appears the last semi colon and number are trimmed off the IPv6  
address,  
for example if I enter the full IPv6 address I get this:

http://[2a02:40:40:7:0:0:0:7]/test.php  
$\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7:0:0:0

I’ve spent a couple of hours trying different scenarios and added custom  
logging to log the value of the $host variable and as far as I can tell  
nginx seems to always incorrectly trim the value of $host for IPv6  
addresses.

Here is an example log entry, with an incorrectly logged host name:

[28/Nov/2010:17:50:08 +0000] [2a02:40:40:7: “GET /test.php HTTP/1.1”

The funny thing is that the correct value is always passed to PHP (for  
direct requests), but the value of $host is always trimmed incorrectly.  
As the host name is passed to the backend server via a proxy\_set\_header  
directive the incorrect value is always passed to the backend and  
therefore  
incorrectly passed to PHP in this instance.

---

<div class="post-metadata">

**Author:** ![phoyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@phoyce](https://www.ruby-forum.com/u/phoyce)\
**Post date:** [November 28, 2010, 10:31pm UTC](https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761/2 "2010-11-28T22:31:42Z")

</div>

Here is debug output showing the problem:

2010/11/28 21:22:37 [debug] 10417#0: accept on [2a02:40:40:7::7]:80,  
ready:  
0  
2010/11/28 21:22:37 [debug] 10417#0: posix\_memalign:  
0000000001031DA0:256  
@16  
2010/11/28 21:22:37 [debug] 10417#0: \*8 accept:  
2001:0:5ef5:79fd:3472:2f12:921f:6666 fd:3  
2010/11/28 21:22:37 [debug] 10417#0: \*8 event timer add: 3:  
60000:1290979417739  
2010/11/28 21:22:37 [debug] 10417#0: \*8 epoll add event: fd:3 op:1  
ev:80000001  
2010/11/28 21:22:37 [debug] 10417#0: \*8 posix\_memalign:  
0000000001063DD0:256  
@16  
2010/11/28 21:22:37 [debug] 10417#0: \*8 malloc: 000000000103FB90:1288  
2010/11/28 21:22:37 [debug] 10417#0: \*8 malloc: 00000000010400A0:1024  
2010/11/28 21:22:37 [debug] 10417#0: \*8 posix\_memalign:  
00000000010404B0:4096 @16  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http process request line  
2010/11/28 21:22:37 [debug] 10417#0: \*8 recv: fd:3 644 of 1024  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http request line: “GET /  
HTTP/1.1”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http uri: “/”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http args: “”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http exten: “”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http process request header line  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header: “Accept:  
application/x-ms-application, image/jpeg, application/xaml+xml,  
image/gif,  
image/pjpeg, application/x-ms-xbap, application/x-shockwave-flash,  
application/vnd.ms-excel, application/vnd.ms-powerpoint,  
application/msword,  
_/_”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header: “Accept-Language:  
en-GB”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header: “User-Agent:  
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0;  
SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media  
Center PC 6.0; InfoPath.2; .NET CLR 1.1.4322; OfficeLiveConnector.1.5;  
OfficeLivePatch.1.3; .NET4.0C; Creative AutoUpdate v1.40.02)”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header: “Accept-Encoding:  
gzip,  
deflate”  
\*2010/11/28 21:22:37 [debug] 10417#0: _8 http header: “Host:  
[2a02:40:40:7::7]”_  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header: “Connection:  
Keep-Alive”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http header done  
2010/11/28 21:22:37 [debug] 10417#0: \*8 event timer del: 3:  
1290979417739  
2010/11/28 21:22:37 [debug] 10417#0: \*8 generic phase: 0  
2010/11/28 21:22:37 [debug] 10417#0: \*8 rewrite phase: 1  
2010/11/28 21:22:37 [debug] 10417#0: \*8 test location: “/”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 using configuration “/”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http cl:-1 max:1048576  
2010/11/28 21:22:37 [debug] 10417#0: \*8 rewrite phase: 3  
2010/11/28 21:22:37 [debug] 10417#0: \*8 post rewrite phase: 4  
2010/11/28 21:22:37 [debug] 10417#0: \*8 generic phase: 5  
2010/11/28 21:22:37 [debug] 10417#0: \*8 generic phase: 6  
2010/11/28 21:22:37 [debug] 10417#0: \*8 generic phase: 7  
2010/11/28 21:22:37 [debug] 10417#0: \*8 access phase: 8  
2010/11/28 21:22:37 [debug] 10417#0: \*8 access phase: 9  
2010/11/28 21:22:37 [debug] 10417#0: \*8 post access phase: 10  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http init upstream, client  
timer: 0  
2010/11/28 21:22:37 [debug] 10417#0: \*8 epoll add event: fd:3 op:3  
ev:80000005  
2010/11/28 21:22:37 [debug] 10417#0: \*8 posix\_memalign:  
0000000001036860:4096 @16  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "Host: "  
\*2010/11/28 21:22:37 [debug] 10417#0: _8 http script var:  
“[2a02:40:40:7:”_  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "X-Real-IP: "  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script var:  
“2001:0:5ef5:79fd:3472:2f12:921f:6666”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy:  
"X-Forwarded-For:  
"  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script var:  
“2001:0:5ef5:79fd:3472:2f12:921f:6666”  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "  
2010/11/28 21:22:37 [debug] 10417#0: \*8 http script copy: "Connection:  
close

---

<div class="post-metadata">

**Author:** ![phoyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@phoyce](https://www.ruby-forum.com/u/phoyce)\
**Post date:** [November 29, 2010, 2:16am UTC](https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761/3 "2010-11-29T02:16:52Z")

</div>

Hello!

On Sun, Nov 28, 2010 at 07:19:17PM +0000, Phil B. wrote:

> Direct request to backend server (works):
> 
> http://[2a02:40:40:7::3]/test.php  
> $\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7::3]
> 
> Via proxy:
> 
> http://[2a02:40:40:7::7]/test.php  
> $\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7:

Known issue, ipv6 address literals not supported.

> **[IPv6 bug](http://mailman.nginx.org/pipermail/nginx/2010-November/023652.html)**

Maxim D.

---

<div class="post-metadata">

**Author:** ![phoyce](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bc8723/32.png) [@phoyce](https://www.ruby-forum.com/u/phoyce)\
**Post date:** [November 29, 2010, 9:07am UTC](https://www.ruby-forum.com/t/ipv6-addresses-for-host-name-are-incorrectly-trimmed-by-nginx/199761/4 "2010-11-29T09:07:42Z")

</div>

On 29 November 2010 01:15, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > If I enter the IPv6 address into the browser, the address is trimmed when  
> > Via proxy:
> > 
> > http://[2a02:40:40:7::7]/test.php  
> > $\_SERVER[‘HTTP\_HOST’] = [2a02:40:40:7:
> 
> Known issue, ipv6 address literals not supported.
> 
> [IPv6 bug](http://nginx.org/pipermail/nginx/2010-November/023652.html)

Thanks for the info, will have to hope that someone has time to fix it  
at  
some point!  
Unfortunately the only way to test via a 6to4 tunnel on an IPv4  
connection  
is to use the full IPv6 address.
