# Proxy\_hide\_header hiding header from ALL locations

**URL:** <https://www.ruby-forum.com/t/proxy-hide-header-hiding-header-from-all-locations/192354>\
**Category:** NGINX\
**Created:** [July 28, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/proxy-hide-header-hiding-header-from-all-locations/192354 "2010-07-28T23:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [July 28, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/proxy-hide-header-hiding-header-from-all-locations/192354/1 "2010-07-28T23:27:31Z")

</div>

I have a two phase setup commonly implemented with S3.

I want to set ETag and Last-Modified in my Rails application and have  
them take precedence over the S3 ETag and Last-Modified.

location ^~ /AWSS3/ {

# Prevent Client headers from going to nginx.

proxy\_pass\_request\_headers off;

# Prevent nginx from overwriting our headers.

proxy\_hide\_header “Content-Type”;  
proxy\_hide\_header “Last-Modified”;  
proxy\_hide\_header “ETag”;  
proxy\_hide\_header “Content-Disposition”;

# Hide Amazon Headers

proxy\_hide\_header X-Amz-Id-2;  
proxy\_hide\_header X-Amz-Request-Id;

# Have Amazon do the work buffering the request.

proxy\_set\_header Host ‘[s3.amazonaws.com](http://s3.amazonaws.com)’; # the bucket is specified in  
the url

# Force Amazon to do the heavy lifting.

proxy\_buffering off;

# Retry if Amazon freaks out

proxy\_next\_upstream error timeout http\_500 http\_502 http\_503 http\_504;

# Ensure the requests are always gets.

proxy\_method GET;  
proxy\_pass\_request\_body off;  
proxy\_set\_header Content-Length “”;

# Proxy to S3.

proxy\_pass [http://s3/](http://s3/);  
proxy\_hide\_header ETag;  
proxy\_hide\_header Last-Modified;

internal;  
}

What I see on my client is a valid Content-Type and  
Content-Disposition set by my Rails application but ETag and  
Last-Modified are not set. If I remove those proxy\_hide\_header  
directives the Headers are present but they are the values S3 returns  
not the values I returned from Rails.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [July 30, 2010, 9:53pm UTC](https://www.ruby-forum.com/t/proxy-hide-header-hiding-header-from-all-locations/192354/2 "2010-07-30T21:53:29Z")

</div>

Hello!

On Wed, Jul 28, 2010 at 02:47:28PM -0700, W. Andrew Loe III wrote:

> How can I get this behavior for ETag and Last-Modified as well?

Aha, now it’s clear that you want to inherit some headers from  
original response with X-Accel-Redirect. Here is the solution:

```
location ... {
    set $x $upstream_http_...;
    add_header Something $x;

    proxy_pass ...
    ...
}

```

Note that you have to use extra “set” to preserve  
$upstream\_http\_… variable from original response.

Maxim D.

---

<div class="post-metadata">

**Author:** ![WSandrew\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d07c76/32.png) [@WSandrew\_L](https://www.ruby-forum.com/u/WSandrew_L)\
**Post date:** [July 28, 2010, 11:48pm UTC](https://www.ruby-forum.com/t/proxy-hide-header-hiding-header-from-all-locations/192354/3 "2010-07-28T23:48:36Z")

</div>

It looks like Content-Type is special cased:

Changes with nginx 0.3.58 14 Aug  
2006

```
*) Feature: the "error_page" directive supports the variables.

*) Change: now the procfs interface instead of sysctl is used on 

```

Linux.

```
*) Change: now the "Content-Type" header line is inherited from 

```

first  
response when the “X-Accel-Redirect” was used.

How can I get this behavior for ETag and Last-Modified as well?
