小编Ric*_*ith的帖子

将 nginx try_files 与多个目录树一起使用

我想让 nginx 通过检查该路径/文件是否存在于几个单独的目录中来处理对特定目录的请求。例如,如果我的根目录具有以下内容:

images/siteA/foo.jpg
images/siteB/b/bar.jpg
images/siteC/example.jpg
Run Code Online (Sandbox Code Playgroud)

我想http://example.com/images/foo.jpg返回文件foo.jpghttp://example.com/b/bar.jpg返回文件bar.jpg等等。

我尝试了以下操作,但它只是被锁定在重定向循环中(我不希望它重定向,但实际上将文件提供给该 URL):

  location /images/ {
    try_files /siteA/images/
              /siteB/images/
              /siteC/images/ =404;

  } 
Run Code Online (Sandbox Code Playgroud)

我也尝试过使用捕获组,例如location ~/images/(.*)/并添加$1到 URL 的末尾。我对文档有点困惑,不确定如何使用 nginx 完成此操作。

configuration nginx

5
推荐指数
2
解决办法
9703
查看次数

标签 统计

configuration ×1

nginx ×1