Index fallback?

Edho Arief me at myconan.net
Mon Oct 10 06:53:58 UTC 2016


Hi,

On Mon, Oct 10, 2016, at 15:50, Nurahmadie Nurahmadie wrote:
> > >
> > > Still need more locations, but independent to directories you want to
> > > access:
> > >
> > >
> > >     server {
> > >             listen 7770;
> > >             root /tmp;
> > >             autoindex on;
> > >             autoindex_format json;
> > >     }
> > >
> > >     server {
> > >             listen       80;
> > >             server_name  localhost;
> > >             index index.html;
> > >             root /tmp;
> > >
> > >             location ~ /.*?[^/]$ {
> > >                     try_files $uri @redir;
> > >             }
> > >
> > >             location @redir {
> > >                     return 301 $uri/;
> > >             }
> > >
> > >             location ~ /$ {
> > >                     try_files $uri"index.html" @reproxy;
> > >             }
> > >
> > >             location @reproxy {
> > >                     proxy_pass http://localhost:7770;
> > >             }
> > >     }
> > >
> >
> > Thanks, but that's even longer than my ifs. Also one `server { }` and
> > one regexp location too many.
> >
> 
> Ah, sorry I thought it's obvious that the other server is just served as
> dummy example,
> also I have this tendency to avoid `if` as much as possible, so yeah
> 

Looking again, that's actually the solution:

location / {
  location ~ /$ {
    try_files $uri/index.html @dirlist;
  }
}

Thanks.



More information about the nginx mailing list