如何让nginx-gridfs正确使用正则表达式位置匹配的结果
简而言之,这不起作用:
location ~* /grid/(.+)/ {
gridfs filestore field=filename type=string root_collection=storage.$1;
}
这是使用 https://github.com/mdirolf/nginx-gridfs
它有很多问题。这只是一个仅供参考,因为我不认为它可以用位置正则表达式来完成,因为:
- 组不是进程,并且 $1 被逐字用作“存储。$1”集合名称
- 不知何故,可能在 C 代码中,文件名是通过从匹配中剥离字符、删除正则表达式中指定的确切字符数来获取的。意思是,“/grid/(.+)/”的长度为 10 个字符,这是从整个 url 中删除的字符数(显然,减去域名)。我对此进行了相当多的测试(不仅仅是通过 C 代码),这就是它正在做的事情。
我假设这仍然可以通过某种方式重写或另一个 nginx 配置来完成。
作为最后的手段,我将联系项目维护者,但 nginx 的配置似乎足够灵活,可以解决这些问题,正如广告中所宣传的那样:
location ~* /grid/ABC/ {
gridfs filestore field=filename type=string root_collection=storage.ABC;
}
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), and 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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论