title: Redirect/Rewrite (in nginx) Requests to Subdirectory to S3-Compatible Bucket
body: <p>I am attempting to get nginx to redirect/rewrite requests to a specific subdirectory so that they are served by an S3-compatible bucket instead of the server. Here is my current server block:</p>
  
  <p><code>{snip}</code> (See <em>infra</em>.)</p>
  
  <p>Despite fiddling with this for some time now, I've only been able to get it to return 404s.</p>
  
  <h2>Additional Information</h2>
  
  <p><a href="https://omnifora.com/t/redirect-rewrite-in-nginx-requests-to-subdirectory-to-s3-compatible-bucket/402" rel="nofollow noreferrer">https://omnifora.com/t/redirect-rewrite-in-nginx-requests-to-subdirectory-to-s3-compatible-bucket/402</a></p>
  
  <h2>Attempts Solutions So Far</h2>
  
  <ol>
  <li><p><code>rewrite</code></p>
  
  <p>rewrite ^/security-now/(.*) $scheme://s3.us-west-1.wasabisys.com/bits-podcasts/security-now/$1;</p></li>
  <li><p><code>return</code></p>
  
  <p>return 302 $scheme://s3.us-west-1.wasabisys.com/bits-podcasts/security-now/$1;</p></li>
  <li><p><code>proxy_pass</code></p>
  
  <p>proxy_set_header Host s3.us-west-1.wasabisys.com;
          proxy_pass $scheme://s3.us-west-1.wasabisys.com/bits-podcasts/security-now/$1;</p></li>
  </ol>