I have a regexp location for a subdirectory (/foo
) and want Nginx to do this for a request to /foo/bar
:
- Check if
bar
is a file or directory in the root defined in the location. If it is a directory, check for the index file. - If there is no file or directory
bar
fallback to the given URI (there is another working handler for .php files).
It looks like this:
location ~ ^/foo(/.*)?$ {
root /my/root/with/files;
index index.php;
try_files $1 $1/ /my/root/with/files/index.php?$args;
}
Should be simple, but I can't get this working, and the documentation does not help. I tried many combinations of alias
, root
and whatever.
Any suggestions, how to get this working? Or do you know where to get useful documentation about try_files, root, alias, locations (including notes about outstanding bugs)?
root
andindex
directives outside of the location as suggested in nginx pitfalls.