I am using fastcgi_cache in nginx in order to speed up the php, which connects database and select articles.
Here is my flow:
first, I add a ssi-include in my index:
<\!--# include file="/templates/1-5-list.html" -->
then, I add a location route to handle html -> php in nginx-conf
location ~(\d*?)-(\d*?)-list.html
{
try_files $uri /articles/list.php?p1=$1&p2=$2;
}
after that, I apply fastcgi_cache
for 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;
...
}
Everything is ok right now, and the caching function well.
However, If I have two or more ssi in my index:
<\!--# include file="/templates/1-5-list.html" -->
<\!--# include file="/templates/2-5-list.html" -->
The second ssi return exactly the same result as the first one, FAIL!
I search inside the cache directory, And I found that, the KEY
using for caching is httplocalhost/articlesGET
, which means such two ssi are sharing the same KEY
. And I think this is the cause.
My question is how can I modify the fastcgi_cache_key
such that they can have different KEY
? I've tried adding fastcgi_cache_key
inside location{}
but fail.
$request_uri
in nginx SSI subrequest refers to parent request URI. Use $uri
in included fragment cache key instead: fastcgi_cache_key $scheme$host$uri$request_method;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.