加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Nginx,memcached和cakephp:memcached模块总是错过缓存

发布时间:2020-12-16 05:53:17 所属栏目:安全 来源:网络整理
导读:我有一个简单的nginx配置; server{ servername localhost; root /var/www/webroot; location / { set_md5 $memcached_key $uri; index index.php index.html; try_files $uri $uri/ @cache; } location @cache { memcached_pass localhost:11211; default_ty

我有一个简单的nginx配置;

server{
  servername localhost;
  root /var/www/webroot;

  location / {
    set_md5  $memcached_key $uri;
    index  index.php index.html;
    try_files $uri $uri/ @cache;
  }

  location @cache  {
    memcached_pass localhost:11211;
    default_type text/html;
    error_page 404  @fallback;
  }

  location @fallback{
    try_files $uri $uri/ /index.php?url=$uri&$args;
  }

  location ~ .php${
    fastcgi_param MEM_KEY $memcached_key;
    include /etc/nginx/fastcgi.conf;
    fastcgi_index  index.php;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
  }
}

我有一个CakePHP助手,它使用MEM_KEY参数将视图保存到memcached中.我已经测试了它并且它正在工作,但是,nginx总是会进入@fallback方向.我该如何解决此问题?可能会出现问题吗?

最佳答案
感谢DukeLion的评论,我终于可以找到发生了什么,nginx正在进入memcached服务器okey,但是cakephp正在改变密钥.

例如,我尝试访问/home_page.html

Nginx使用/home_page.html进入内存缓存,不要找到它,因此加载cakephp,cakephp生成视图并将其保存在密钥_home__page_html中

解决方案是扩展memcached cakephp引擎.

谢谢!!!

pd:您可以在http://andy-gale.com/cakephp-view-memcache.html中获取memcached视图引擎的示例

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读