proxy_hide_header hiding header from ALL locations

W. Andrew Loe III andrew at
Thu Jul 29 01:26:44 MSD 2010

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 ''; # 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;


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.

More information about the nginx mailing list