How to make nginx-gridfs properly use the result of regex location match
In short, this doesn't work:
location ~* /grid/(.+)/ {
gridfs filestore field=filename type=string root_collection=storage.$1;
}
This is using https://github.com/mdirolf/nginx-gridfs
There are multiple problems with it. This is just an FYI, as I don't think it can be done with location regex, because of:
- group is not processes, and $1 is being used verbatim as a "storage.$1" collection name
- Somehow, probably in the C code, file name is picked up by stripping characters from the match, by removing exact number of characters that is specified in regex. Meaning, "/grid/(.+)/" is 10 characters long, and this is how many characters are stripped from the entire url (minus domain, obviously). I've tested this quite a bit (short from just going through C code), an开发者_开发问答d this is what it's doing.
I'm assuming this can be still done with rewrite somehow or another nginx config.
As a last resort, I'll reach out to the project maintainer, but nginx's configuration is flexible enough, it seems, to work around the issues, as this works as advertized:
location ~* /grid/ABC/ {
gridfs filestore field=filename type=string root_collection=storage.ABC;
}
精彩评论