Index fallback?

Edho Arief me at myconan.net
Sun Oct 16 08:01:36 UTC 2016


Hi,

Just updating myself, I realized I don't even need any weird setup, just
change the fallback location from

location @something { }

into

location = /.something { }

and set index parameter to

index index.html /.something;

It works because the last element of the list can be an absolute path as
mentioned in documentation.


On Mon, Oct 10, 2016, at 12:56, Edho Arief wrote:
> I somehow can't make this scenario work:
> 
> root structure:
> /a/index.html
> /b/ <-- no index.html
> 
> accessing:
> 1. site.com/a -> redirect to site.com/a/ -> show /a/index.html
> 2. site.com/b -> redirect to site.com/b/ -> show @fallback
> 
> 
> Using
> 
> try_files $uri $uri/index.html @fallback;
> 
> doesn't work quite well because #1 becomes this instead:
> 
> 1. site.com/a -> show /a/index.html
> 
> and breaks relative path javascript/css files (because it's `/a` in
> browser, not `/a/`).
> 
> And using
> 
> try_files $uri @fallback;
> 
> Just always show @fallback for both scenarios.
> 
> Whereas
> 
> try_files $uri $uri/ @fallback;
> 
> Always return 403 for #2 because the directory exists and there's no
> index.
> 
> As a side note,
> 
> error_page 404 = @fallback;
> 
> Wouldn't work because as mentioned in the previous one, it returns 403
> for #2 (directory exists, no index), not 404.
> 
> Is there any way to do it without specifying separate location for each
> of them?



More information about the nginx mailing list