FAQ Suggestions

nanaya me at nanaya.net
Sun Feb 19 06:26:51 UTC 2023


Hi

On Sun, Feb 19, 2023, at 10:27, Ivo Welch wrote:
> 2. why does
>
> ```
> location /wth {
>    root /var/www/fcgi-bin/;
>    index wth-root.html;
>  }
> ```
>
> not resolve '/wth' (but incidentally does resolve '/wth-root.html',
> though not '/wth-root').
>

it's one of the common confusions. Just /wth doesn't trigger index listing as it doesn't end with a forward slash. /wth-root does match because /wth matches anything that starts with /wth (some people seem to think it matches /wth/ directory but it really doesn't - it's just prefix matching after all).

If you have /var/www/fcgi-bin/wtha.html file and try accessing /wtha.html, it'll return that file, for example. Same with /wth-root.html as you experienced. 

Back to /wth, it'll try to return file /var/www/fcgi-bin/wth (which probably doesn't exist).

If what you actually want is to to match /wth/, it needs to be `location /wth/`. Although then it can't be accessed through /wth as it doesn't match anymore (unless it exists as directory in other location like `location /`). In which case I usually add `location = /wth { return 302 /wth/; }` to fix this one special case.


More information about the nginx mailing list