Nginx, memcached and cakephp: memcached module always misses cache

Posted by Tim on Server Fault See other posts from Server Fault or by Tim
Published on 2012-06-01T02:21:53Z Indexed on 2012/06/01 4:42 UTC
Read the original article Hit count: 748

Filed under:
|
|
|

I've got a simple nginx configuration;

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

  location / {
    set  $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;
  }
}

I've got a CakePHP helper that saves the view into memcached using the MEM_KEY parameter. I have tested it and it's working, however, nginx is always going to the @fallback direction. How can I go about troubleshooting this behavior? Would could the problem be?

© Server Fault or respective owner

Related posts about nginx

Related posts about cache