Permalink
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (44 sloc) 2.38 KB

NGINX Configuration

Below you will find detailed NGINX configuration recommendations for the features provided by this library. The examples are tested with NGINX version 1.4.6.

NGINX cache is a set of key/value pairs. The key is built with elements taken from the requests (URI, cookies, http headers etc) as specified by proxy_cache_key directive.

When we interact with the cache to purge/refresh entries we must send to NGINX a request which has the very same values, for the elements used for building the key, as the request that create the entry. In this way NGINX can build the correct key and apply the required operation to the entry.

By default NGINX key is built with $scheme$proxy_host$request_uri. For a full list of the elements you can use in the key see this page from the official documentation.

Purge

NGINX does not support :term:`purge` functionality out of the box but you can easily add it with ngx_cache_purge module. You just need to compile NGINX from sources adding ngx_cache_purge with --add-module.

You can check the script :source:`install-nginx.sh <tests/install-nginx.sh>` to get an idea about the steps you need to perform.

Then configure NGINX for purge requests:

.. literalinclude:: ../tests/Functional/Fixtures/nginx/fos.conf
    :language: nginx
    :linenos:
    :emphasize-lines: 41, 47-53

Please refer to the ngx_cache_purge module documentation for more on configuring NGINX to support purge requests.

Refresh

If you want to invalidate cached objects by forcing a :term:`refresh` you have to use the built-in proxy_cache_bypass directive. This directive defines conditions under which the response will not be taken from a cache. This library uses a custom HTTP header named X-Refresh, so add a line like the following to your config:

.. literalinclude:: ../tests/Functional/Fixtures/nginx/fos.conf
    :language: nginx
    :lines: 44

Debugging

Configure your Nginx to set a custom header (X-Cache) that shows whether a cache hit or miss occurred:

add_header X-Cache $upstream_cache_status;