【问题标题】:nginx cache check with try_files使用 try_files 检查 nginx 缓存
【发布时间】:2017-02-10 07:12:03
【问题描述】:

我有一个写入缓存目录的图像服务器(目前它只是在 url 请求中使用相同的路径)。我已经确认在初始请求(即缓存中没有任何内容)中写入了一个新文件,但是在后续请求中,try_files 没有成功找到该文件。

我的nginx.conf 是:

http {
    server {
        listen 8080;
        # serve tiles if not in the cache
        location @image_server {
          content_by_lua_file "/Users/tim/work/chickpea/serve_image.lua";
        }

        # capture tile request e.g. /tile/l8/091080/rgb/20160924/10/938/597.jpg
        # regex named capture groups for each param
        location ~ ^/tile/(?<layer>[^/]+)/(?<pathrow>[^/]+)/(?<type>[^/]+)/(?<date>[^/]+)/(?<z>[^/]+)/(?<x>[^/]+)/(?<y>[^.]+) {
          root cache;
          set $cachepath "cache/$layer/$pathrow/$type/$date/$z/$x/$y.jpg";
          try_files $cachepath @image_server;
          add_header X-Static hit;
        }

        ..

我已确认应/tile/l8/091080/rgb/20160924/10/938/597.jpg 的请求,$cachepathcache/l8/091080/rgb/20160924/10/938/597.jpg,并且597.jpg 位于正确的路径中。我已经尝试了一个有和没有前导 cache/ 的 $cachepath ,但似乎都不起作用。

【问题讨论】:

    标签: caching nginx lua


    【解决方案1】:

    完成这项工作需要进行两项更改:

    1. 使root 指令成为绝对路径,否则它实际上是/usr/local/nginx/cache

    2. $cachepath 变量添加一个前导正斜杠。由于根指令值和$cachepath 被附加在一起以确定完整的文件路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      相关资源
      最近更新 更多