title: Nginx proxy Amazon S3 resources
body: <p>I´m performing some WPO tasks, so PageSpeed suggested me to leverage browser caching. I have improved it successfully for some static files in my Nginx server, however my image files stored in Amazon S3 server are still missing. </p>
  
  <p>I have read an approach regarding update each file in S3 to include some header metatags (Expires and Cache-Control). I think this is not a good approach. I have thousands of files, so this is not feasible for me.</p>
  
  <p>I think a most convenient approach is to configure my Nginx 1.6.0 server to proxy the S3 files. I have read about this, but I´m not skilled at all on server config, so I got a couple examples from these sites: <a href="https://gist.github.com/benjaminbarbe/1961db5ffbaad57eff12" rel="noreferrer">https://gist.github.com/benjaminbarbe/1961db5ffbaad57eff12</a> </p>
  
  <p>I added this location code inside my server block in my nginx config file:</p>
  
  <pre><code>#inside server block
  location /mybucket.s3.amazonaws.com/ {
  
  
          proxy_http_version     1.1;
          proxy_set_header       Host mybucket.s3.amazonaws.com;
          proxy_set_header       Authorization '';
          proxy_hide_header      x-amz-id-2;
          proxy_hide_header      x-amz-request-id;
          proxy_hide_header      Set-Cookie;
          proxy_ignore_headers   "Set-Cookie";
          proxy_buffering        off;
          proxy_intercept_errors on;      
          proxy_pass             http://mybucket.s3.amazonaws.com;
        }
  </code></pre>
  
  <p>For sure, this is not working for me. No header is included in my requests. So, first I think the requests are not matching the locations.</p>
  
  <pre><code>Accept-Ranges:bytes
  Content-Length:90810
  Content-Type:image/jpeg
  Date:Fri, 23 Jun 2017 04:53:56 GMT
  ETag:"4fd0be549fbcaf9b47c18a15146cdf16"
  Last-Modified:Tue, 09 Jun 2015 09:47:13 GMT
  Server:AmazonS3
  x-amz-id-2:cKsq1qRra74DqVsTewh3P3sgzVUoPR8aAT2NFCuwA+JjCdDZfk7/7x/C0WPjBa51GEb4C8LyAIc=
  x-amz-request-id:94EADB4EDD3DE1C1
  </code></pre>