Serve index.html file if exists try_files + proxy_pass?

Francis Daly francis at
Mon May 1 12:08:11 UTC 2017

On Mon, May 01, 2017 at 01:50:10PM +0200, Lucas Rolff wrote:

Hi there,

Thanks for the extra explanation. It is clear to me now.

> When I access<bucket>/ Minio will generate an
> XML containin a list of objects within a specific bucket (as per S3
> API standards).
> Example:
> Since I do not want to expose this bucket object list, I want to do
> so if a bucket has the file "index.html" that it will serve this,
> instead of showing the bucket object list.


For info: that *will* expose the bucket object list if there is no

You may prefer a static fallback page, or an error indication instead.

> If I access - it should look for the
> file /home/minio/images/index.html and serve if existing else load
> the bucket object list (basically, just proxy_pass as normal).
> Any other request I do such as
> should go to my
> upstream server (localhost:9000)

> If I do try_files index.html @upstream;
> Then try_files will base it on the root directive defined, in this
> case it would try look for /home/minio/index.html if I set the root
> directive to "/home/minio", correct?


> I guess I could take try_files "${uri}index.html" @upstream; which
> would produce something like /home/minio/storage/index.html if you
> have /storage/ as the URI, but if URI is /storage/image1.png it
> would try to look for "/home/minio/storage/image1.pngindex.html" and
> for me that doesn't seem very efficient, since it would have to stat
> for a file on the file system for every request before actually
> going to my upstream.

Also correct.

> I could maybe do:
> location / {
>   location ~ /$ {
>     try_files "${uri}index.html" @upstream;
>   }
>   // continue normal code here
> }
> location @upstream {
>   proxy_pass;
> }

That is what I would suggest. Where "// continue normal code here" is
"proxy_pass;". And "root /home/minio;" is set
somewhere so that it applies where try_files is.

Good luck with it,

Francis Daly        francis at

More information about the nginx mailing list