在nginx

时间:2017-05-02 08:56:12

标签: caching nginx fastcgi ssi

我在nginx中使用fastcgi_cache来加速连接数据库和选择文章的php。

这是我的流程:

首先,我在索引中添加了一个ssi-include:

<\!--# include file="/templates/1-5-list.html" -->

然后,我添加一个位置路由来处理html - &gt; php在nginx-conf中

location ~(\d*?)-(\d*?)-list.html
{
    try_files $uri /articles/list.php?p1=$1&p2=$2;
}

之后,我将fastcgi_cache应用于list.php

# outside the server{}
    fastcgi_cache_path /home/cache/articles levels=1 keys_zone=articles_cache:10m max_size=1024m inactive=1h;
    fastcgi_cache_key $scheme$host$request_uri$request_method;
# outside the server{}

location ~/list.php$ {
    fastcgi_cache articles_cache;
    fastcgi_cache_valid 200 2h;
    ...
}

现在一切都很好,缓存功能也很好。

但是,如果我的索引中有两个或更多个ssi:

<\!--# include file="/templates/1-5-list.html" -->
<\!--# include file="/templates/2-5-list.html" -->

第二个ssi返回与第一个完全相同的结果,FAIL!

我在缓存目录中搜索,我发现,用于缓存的KEYhttplocalhost/articlesGET,这意味着这两个ssi共享相同的KEY。而且我认为这是原因。

我的问题是如何修改fastcgi_cache_key以便他们可以有不同的KEY?我尝试在fastcgi_cache_key内添加location{},但失败了。

1 个答案:

答案 0 :(得分:0)

nginx中的

$request_uri SSI子请求是指父请求URI。 改为使用包含的片段缓存键中的$uri fastcgi_cache_key $scheme$host$uri$request_method;

相关问题