# FastCGI cache (WordPress)

**URL:** <https://www.ruby-forum.com/t/fastcgi-cache-wordpress/199522>\
**Category:** NGINX\
**Created:** [November 23, 2010, 8:03am UTC](https://www.ruby-forum.com/t/fastcgi-cache-wordpress/199522 "2010-11-23T08:03:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 23, 2010, 8:03am UTC](https://www.ruby-forum.com/t/fastcgi-cache-wordpress/199522/1 "2010-11-23T08:03:03Z")

</div>

I’m trying to set up fastcgi\_cache with nginx+php-fpm. I can see  
directories appearing in my cache dir, but pages that I expect to return  
a cached hit, are downloaded (0 kb files) rather than served as a web  
page. I can see why it might be the default\_type setting, but I don’t  
know what else to set it to, or how to override the setting inside the  
location block.

```auto
user www-data;
worker_processes 4;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  server_names_hash_max_size 512;
  server_names_hash_bucket_size 128;

  index index.php index.html index.htm;

  include mime.types;
  default_type application/octet-stream;

  fastcgi_cache_path /var/cache/nginx levels=1:2
keys_zone=WORDPRESS:10m inactive=5m;

  access_log /var/log/nginx/access.log;
  sendfile on;

  keepalive_timeout 65;

  gzip on;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

server {
  listen 127.0.0.1:80 default;
  server_name www.mysite.com;

  error_log /var/log/nginx/www.mysite.com-error.log;
  access_log /var/log/nginx/www.mysite.com-access.log;

  root /home/graq/sites/www.mysite.com;

  location / {
    try_files $uri $uri/ /index.php?q=$uri&$args;
  }

  location ~ \.php$ {
    set $wordpress_logged_in "";
    set $comment_author_email "";
    set $comment_author "";

    if ($http_cookie ~* "wordpress_logged_in_[^=]*=([^%]+)%7C") {
      set $wordpress_logged_in wordpress_logged_in_$1;
    }

    if ($http_cookie ~* "comment_author_email_[^=]*=([^;]+)(;|$)") {
      set $comment_author_email comment_author_email_$1;
    }

    if ($http_cookie ~* "comment_author_[^=]*=([^;]+)(;|$)") {
      set $comment_author comment_author_$1;
    }

    set $my_cache_key
"$scheme://$host$uri$is_args$args$wordpress_logged_in$comment_author_email$comment_author";

    fastcgi_pass_header Set-Cookie;
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_cache_key $my_cache_key;
    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid 200 1m;

    fastcgi_pass unix:/usr/local/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    include fastcgi_params;
  }
}

```

Posted at Nginx Forum:

> **[FastCGI cache (WordPress)](https://forum.nginx.org/read.php?2,152566,152566#msg-152566)**
>
> I'm trying to set up fastcgi\_cache with nginx+php-fpm. I can see directories appearing in my cache dir, but pages that I expect to return a cached hit, are downloaded (0 kb files) rather than served as a web page. I can see why it might be the...
