Nginx Proxy – How to Proxy S3 Public Bucket Hosted by Minio

amazon s3minionginxreverse-proxy

I'm trying to do what I would have thought was the easiest proxy directive in the world, proxying a public S3 bucket.

This is my config:

server {
    listen 80;
    listen [::]:80;

    server_name experiment.local;
    location /404.html {
      proxy_pass https://minio/bucket/404.html;
    }
    location / {
      error_page 404 = /404.html;
      proxy_pass https://minio/bucket/;
    }
}

What actually happens when fetching a page that does not exist in the bucket I get something like this from nginx:

<Error>
  <Code>NoSuchKey</Code>
  <Message>The specified key does not exist.</Message>
  <Key>index.html1</Key>
  <BucketName>visar</BucketName>
  <Resource>/bucket/index.html1</Resource>
  <RequestId>SCRUBBED</RequestId>
  <HostId>SCRUBBED</HostId>
</Error>

I've tried various variants of this but always get similar results. nginx is forwarding the HTTP return code properly so I do get a 404 (originally I got a 200 with my one-liner proxy_pass).

I know I am doing something really basic really wrong I just can't put my finger on it.

Best Answer

server {


    listen 80;
    listen [::]:80;

    server_name experiment.local;
    location /404.html {
      proxy_pass https://minio/bucket/404.html;
    }
    location / {
      proxy_pass https://minio/bucket/;
      proxy_intercept_errors on;
      error_page 404 = /404.html;
    }

}

Apparently ordering matters somewhat.