如何使用具有2个或更多根的try_files [英] How to use try_files with 2 or more roots

查看:226
本文介绍了如何使用具有2个或更多根的try_files的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看上去很低调,没有找到这样的实现方式,并且想知道我尝试的方法是否可能.我有3条提供静态内容的相对路径:

I have looked hi and low and found no such implementation and am wondering if what I am trying is even possible. I have 3 relative paths that serve up static content:

Path1: /usr/local/www/style1/static/...
Path2: /usr/local/www/style2/static/...
Path3: /usr/local/www/style3/static/...

这3个不同的根本身是静态的,但是/static向下的内容仅是半静态的(可能有所不同,具体取决于要提供的确切文件,并且可能存在于一个路径中,而不会存在于另一个路径中).例如

The 3 different roots are static unto themselves but the content from /static on down is only semi-static (might be a bit different depending on the exact file being served up and may exist in one path and not in another). For example

/static/css/custom.css
/static/css/form/button.css
/static/css/form/images/buttondisabled.png
/static/images/ui/buttons/add_item.png
/static/images/ui/menu/help.png

以下是我想做的.基本上是这样,如果请求了"/static"内容,我想检查与path1相关的相对路径,如果在那里找不到,则检查与path2相关的相对路径,如果没有找到,则检查与path3相关的相对路径.这似乎很简单,但我还没有找到任何示例来概述如何完成此操作.我是否可以将3个不同的根设置为变量:

The following is what I would like to do. Which is basically, if "/static" content is requested I want to check the relative path associated with path1 and if not found there then check the relative path associated with path2 and if not found check the relative path associated with path3. This seems fairly simple but I have not found any examples that outline how this might be done. Could I set the 3 different roots up as variables perhaps:

path1root /usr/local/www/style1;
path2root /usr/local/www/style2;
path3root /usr/local/www/style3;

location /static
{
    try_files path1root/$uri path2root/$uri path3root/$uri (=404);
}

或者可以这样做,因为只需要/static内容:

Or might that be done as follows since it is only needed for /static content:

location /static
{
    path1root /usr/local/www/style1;
    path2root /usr/local/www/style2;
    path3root /usr/local/www/style3;

    try_files path1root/$uri path2root/$uri path3root/$uri (=404);
}

或者我想做的事情根本可以做吗?如果我不能用3个根来做到这一点,那么可以只用2个根来完成,而不必将其中一个定义为整体的弓形基根.如果可以做到这一点,并避免使用正则表达式会更好-但是,如果需要这样做,那么就需要这样做.

Or can what I am attempting to do even be done at all ?? If I cannot do it with 3 roots could it be done with just 2 roots without defining one of them as an overall arching base root. If it is possible to do this and stay away from regular expressions that would be better -- but if that is needed then that is needed.

推荐答案

您可以使用公共根目录并尝试try_files语句中的三个目录:

You could use a common root and try the three directories in the try_files statement:

location /static {
    root /usr/local/www;
    try_files /style1$uri /style2$uri /style3$uri =404;
}

这篇关于如何使用具有2个或更多根的try_files的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆