Basic Example: WordPress Proxy Caching with FastCGI

I would like to add caching to various wordpress installations (some
bloggy, some not). There are no caching plugins installed, as I’d like
nginx to handle the caching.

The current setup is fairly basic:

server {

  root  /home/httpd/wordpress/;
  index index.php index.html index.htm;

  access_log /var/log/nginx/wordpress/;
  error_log  /var/log/nginx/wordpress/;

  if ($host != '') {
    rewrite ^/(.*)$$1 redirect;

  location / {
    try_files /system/maintenance.html $uri $uri/

  location ~ \.php($|/) {
    set $script     $uri;
    set $path_info  "";

    if ($uri ~ "^(.+\.php)(/.+)") {
      set $script     $1;
      set $path_info  $2;

    include wordpress/fcgi_generic_params.conf;

And the fcgi config:


fastcgi_pass localhost:8887;

fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME

$document_root$fastcgi_script_name; # same path as above

fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  PATH_INFO          $path_info;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  REDIRECT_STATUS    200;


My questions are:

  1. How do I add caching to this?
  2. How do I avoid caching admin pages?
  3. What are the ways to expire generic caches as and when needed?

I have looked at various bits of documentation and blogs. They
predominantly focus on using Apache, which I am not using. I’m unclear
as to which blocks I should be putting the proxy* configurations.
There are multiple WP blogs (and PHP applications generally) served by
nginx, so the cache needs to be able to handle that (i.e. only cache
wordpress configs, not the other stuff).

(apologies for doubling posting, but ‘how to’ doesn’t seem to get much

Posted at Nginx Forum:,126863,126863#msg-126863

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs