Details of Nginx Cache Controller Setting

The basic usage of Nginx Cache Controller plugin has been described in “How to use Nginx Cache Controller“, and this time, we are going to tell you the details of the plugin’s settings.

NOTICE: Amimoto AMI has already set up the settings so you don’t need to change the settings.

Nginx Cache Controller default settings are already entered as you see it at the first time.

Expiration Settings of Cache

Nginx Cache Controller can configure the expiration time for each page type.

Screen Shot 2015-03-05 at 11.15.46

This expiration time is defined by using X-Accel-Expires header and telling the time to the reverse proxy.

However, the default settings of Nginx ignores the X-Accel-Expires header received from fastcgi, so it is required to add the settings below to grant a permit to accept some response headers including A-Accel-Expires.

For example, it is configured as below for the default of Amimoto AMI.

location ~ \.php$ {
    ...
    ...
    fastcgi_pass_header "X-Accel-Redirect";
    fastcgi_pass_header "X-Accel-Buffering";
    fastcgi_pass_header "X-Accel-Charset";
    fastcgi_pass_header "X-Accel-Expires";
    fastcgi_pass_header "X-Accel-Limit-Rate";
    ...
}

Setting for Deleting Cache Automatically

To delete cache automatically, the settings below must be required:

  • Enable Flush Cache is set to Yes.
  • The path of cache that Nginx Cache Controller expects and the path of the reverse proxy cache are same.
  • WordPress (backend web server) has a permission to write on the cache of reverse proxy.

Screen Shot 2015-03-05 at 11.17.48

So, the settings of Nginx are below:

proxy_cache_path

An example of Nginx settings for matching the default settings of Nginx Cache Controller:

proxy_cache_path  /var/cache/nginx levels=1:2
    keys_zone=czone:32m max_size=256m inactive=1440m;

Here is the example from Amimoto AMI.

proxy_cache_path  /var/cache/nginx/proxy_cache levels=1:2
    keys_zone=czone:32m max_size=256m inactive=1440m;

The important parts of above are the path of /var/cache/nginx and /var/cache/nginx/proxy_cache, and the value of levels of 1:2 .

When these settings don’t match the ones of Nginx Cache Controller, it can’t find the cache path, so you can’t delete cache.

Screen Shot 2015-03-05 at 11.21.37

proxy_cache_key

Nginx reverse proxy creates a cache for each request from a browser, and saves it as a file name that is generated from the value of proxy_cache_key with md5 hash.

Nginx Cache Controller assumes the value of proxy_cache_key as below and delete cache.

proxy_cache_key "$scheme://$host$request_uri"

So, if the setting is wrong, it will be impossible to delete the cache because the right name of cache can’t be obtained.

You can change the value by nginxchampuru_get_reverse_proxy_key filter hood in Nginx Cache Controller, though also you need to change the value of the reverse proxy.