【问题标题】:How does uwsgi cache non-text/html content?uwsgi 如何缓存非文本/html 内容?
【发布时间】:2016-03-13 19:41:59
【问题描述】:

有人能解释一下the uwsgi docs 的以下 sn-p 是如何工作的吗?

cache2 = name=mycache,items=100
; load the mime types engine
mime-file = /etc/mime.types

; at each request starting with /img check it in the cache (use mime types engine for the content type)
route = ^/img/(.+) cache:key=/img/$1,name=mycache,mime=1

; at each request ending with .css check it in the cache
route = \.css$ cache:key=${REQUEST_URI},name=mycache,content_type=text/css

; fallback to text/html all of the others request
route = .* cache:key=${REQUEST_URI},name=mycache

; store each successful request (200 http status code) in the 'mycache' cache using the REQUEST_URI as key
route = .* cachestore:key=${REQUEST_URI},name=mycache

既然 ${REQUEST_URI} 用于存储缓存中的所有内容,但 ${REQUEST_URI} 的一部分用于检查缓存中的图像,这应该如何工作?我确实用 log: routing target 输出了 ${REQUEST_URI},它等于每次从第一个 / 开始的完整请求。

在我的设置中类似的东西不起作用(我使用 /usr/local/etc/nginx/mime.types 作为 mime 类型文件)。

谢谢, 吨。

【问题讨论】:

    标签: uwsgi


    【解决方案1】:

    仔细看这一行:

    route = ^/img/(.+) cache:key=/img/$1,name=mycache,mime=1
    

    它将捕获对/img/ 目录中文件的所有请求,并将其相对于/img/ 的路径保存在变量$1 中。现在它向缓存请求密钥/img/$1,所以它会将/img/粘在保存路径的开头。

    对于文件/img/my_logo.png,它会将“my_logo.png”保存在$1变量中,然后将“/img/”粘在保存路径的开头,所以最后会查询/img/my_logo.png .

    基本上,它会重新创建REQUEST_URI。因此,如果它不适合您,请确保您在正则表达式和缓存键中使用相同的基本目录名称。

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 2014-05-07
      相关资源
      最近更新 更多