# Nginx changes the hostname of proxy\_pass into ip address unwantedly

**URL:** <https://www.ruby-forum.com/t/nginx-changes-the-hostname-of-proxy-pass-into-ip-address-unwantedly/243538>\
**Category:** NGINX\
**Created:** [December 2, 2015, 9:00am UTC](https://www.ruby-forum.com/t/nginx-changes-the-hostname-of-proxy-pass-into-ip-address-unwantedly/243538 "2015-12-02T09:00:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 2, 2015, 9:00am UTC](https://www.ruby-forum.com/t/nginx-changes-the-hostname-of-proxy-pass-into-ip-address-unwantedly/243538/1 "2015-12-02T09:00:54Z")

</div>

I have configured nginx to use mod\_zip to zip up multiple files.

I also have configured nginx so that it proxies to s3 when our server  
gets a  
request to /images.

location /p/ {  
proxy\_pass [http://bucket-name.s3.amazonaws.com](http://bucket-name.s3.amazonaws.com);  
}  
When I access a file via \< server \>/images/foo.png, everything works  
great.

However, when I try using mod\_zip, the  
[http://bucket-name.s3.amazonaws.com](http://bucket-name.s3.amazonaws.com)  
gets rewritten to an ip address

[http://54.231.176.194:80/foo.png](http://54.231.176.194:80/foo.png)

S3 needs the bucket-name in the url and gives me a NoSuchBucket error  
when I  
try using the ip address

I get the following error

2015/12/01 01:37:08 [error] 14955#0: \*16 mod\_zip: a subrequest returned  
400,  
aborting… while reading response header from upstream, client:  
172.31.10.100, server: [convoygarage.com](http://convoygarage.com), request: “GET /api/get\_zipfile  
HTTP/1.1”, subrequest: “/p/foo.png”, upstream: “http://  
54.231.176.194:80/foo.png”, host: “[convoygarage.com](http://convoygarage.com)”

Why is nginx or mod\_zip rewriting the hostname portion of my s3 URL into  
an  
ip address?

Posted at Nginx Forum:

> **[nginx changes the hostname of proxy\_pass into ip address unwantedly](https://forum.nginx.org/read.php?2,263199,263199#msg-263199)**
>
> I have configured nginx to use mod\_zip to zip up multiple files. I also have configured nginx so that it proxies to s3 when our server gets a request to /images. location /p/ { proxy\_pass http://bucket-name.s3.amazonaws.com; } When I access a fi

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 2, 2015, 5:05pm UTC](https://www.ruby-forum.com/t/nginx-changes-the-hostname-of-proxy-pass-into-ip-address-unwantedly/243538/2 "2015-12-02T17:05:53Z")

</div>

Hello!

On Tue, Dec 01, 2015 at 08:42:43PM -0500, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, when I try using mod\_zip, the [http://bucket-name.s3.amazonaws.com](http://bucket-name.s3.amazonaws.com)  
> aborting… while reading response header from upstream, client:  
> 172.31.10.100, server: [convoygarage.com](http://convoygarage.com), request: “GET /api/get\_zipfile  
> HTTP/1.1”, subrequest: “/p/foo.png”, upstream: “http://  
> 54.231.176.194:80/foo.png”, host: “[convoygarage.com](http://convoygarage.com)”
> 
> Why is nginx or mod\_zip rewriting the hostname portion of my s3 URL into an  
> ip address?

Note that “upstream” as logged to error log shows an IP address of  
a particular server used, not a host name used in the request.  
This is intentional behaviour to make it easy to debug which  
backend server caused an error.

To find out what was in fact sent in the Host request header  
you’ll have to look into debugging log (or use tcpdump to see what  
is actually sent though the wire).

–  
Maxim D.

> **[nginx](http://nginx.org/)**
