Nginx try_files(文件夹+文件)后备
给定这个文件夹结构:
root folder
+ default
+ settings1.txt
+ settings2.txt
...
+ settingsN.txt
+ user00001
+ settings1.txt
...
...
+ userN
+ settings1.txt
...
以及这个示例 url:
domain.com/user00009/settings1.txt
或者
domain.com/xavi/somefile.txt
我想编写一个让我这样做的规则:
folder exists ? check file : 404
file exists ? serve users file : serve default file
我尝试使用 try_files 但我认为我只能使用 $uri 我得到了整个 url,如果我可以使用,那就太好了slugs ( $1 = user00009 & $2 = settings1.txt )
然后也许我可以输入:
location / {
root /...
try_files $1/$2 default/$2 =404;
}
有什么想法吗?
注意:我知道我可以从 nginx 外部(在本例中为 django )服务器文件,但我试图加快速度
Given this folder structure:
root folder
+ default
+ settings1.txt
+ settings2.txt
...
+ settingsN.txt
+ user00001
+ settings1.txt
...
...
+ userN
+ settings1.txt
...
And this example url:
domain.com/user00009/settings1.txt
Or
domain.com/xavi/somefile.txt
I would like to write a rule that let me do:
folder exists ? check file : 404
file exists ? serve users file : serve default file
I tried using try_files but I think I can only use $uri i get the whole url, would be great if I could work with the slugs ( $1 = user00009 & $2 = settings1.txt )
Then maybe I could put:
location / {
root /...
try_files $1/$2 default/$2 =404;
}
Any idea?
Note: I know i could server the files from outside nginx ( in this case django ) but Im trying to speed things up
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)