Proxy_hide_header hiding header from ALL locations

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’; # 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/;
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.

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.

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs