簡體   English   中英

在Nginx中將許多ssi與fastcgi_cache一起使用

[英]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!

我在緩存目錄中搜索,發現用於緩存的KEYhttplocalhost/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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM