开发者

How to make nginx-gridfs properly use the result of regex location match

开发者 https://www.devze.com 2023-04-13 01:04 出处:网络
In short, this doesn\'t work: location ~* /grid/(.+)/ { gridfs filestore field=filename type=string root_collection=storage.$1;

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:

  1. group is not processes, and $1 is being used verbatim as a "storage.$1" collection name
  2. 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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号