使用 nginx 提供基于查询变量的静态或动态文件


Serving either a static or dynamic file based on a query variable using nginx

>我有一个php脚本,可以转换图像缩略图并将其保存到指示其大小的文件夹中。

例如,通过转到像"http://website.com/thumbs/640x480/image.jpg"这样的 url,缩略图将被创建并保存在与 url 匹配的文件夹中,以便下次静态提供图像。php 脚本使用以下位置块:

location /thumbs/ {
    try_files $uri /thumbs/index.php?r=$uri&$query_string;
}

我想做的是重新生成缩略图图像,如果有一个查询参数,例如附加到缩略图 url ?nocache=1

我认为你需要这样的东西:

location /thumbs/ {
   if ($arg_nocache) {
       rewrite ^(.*)$ /thumbs/index.php?r=$uri&$query_string break;
   }

    try_files $uri /thumbs/index.php?r=$uri&$query_string;
}