[英]use many ssi with fastcgi_cache in nginx
我在nginx中使用fastcgi_cache来加快php的速度,该php连接数据库并选择文章。
这是我的流程:
首先,我在索引中添加一个ssi-include:
<\!--# include file="/templates/1-5-list.html" -->
然后,我在nginx-conf中添加了一个处理html-> php的位置路由
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!
我在缓存目录中搜索,发现用于缓存的KEY
是httplocalhost/articlesGET
,这意味着这两个ssi共享同一个KEY
。 我认为这是原因。
我的问题是如何修改fastcgi_cache_key
以便它们可以具有不同的KEY
? 我曾尝试在location{}
添加fastcgi_cache_key
但失败了。
Nginx SSI子请求中的$request_uri
引用父请求URI。 在包含的片段缓存键中使用$uri
代替: fastcgi_cache_key $scheme$host$uri$request_method;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.