Mastering Nginx

(Ron) #1

Reverse Proxy Advanced Topics


[ 108 ]

Using this configuration, NGINX will set up a series of directories under /var/spool/


nginx that will first differentiate on the last character of the MD5 hash of the URI,
followed by the next two characters from the last. For example, the response for "/


this-is-a-typical-url" will be stored as:


/var/spool/nginx/3/f1/614c16873c96c9db2090134be91cbf13

In addition to the proxy_cache_valid directive, a number of headers control how


NGINX caches responses. The header values take precedence over the directive.



  • The X-Accel-Expires header can be set by the upstream server to control
    cache behavior:


° An integer value indicates the time in seconds for which
a response may be cached

° If the value of this header is 0 , caching for that response
is disabled completely


  • A value beginning with @ indicates the time in seconds since the epoch.
    The response is valid only up to this absolute time.

  • The Expires and Cache-Control headers have the same precedence level.

  • If the value of the Expires header is in the future, the response will be
    cached until then.

  • The Cache-Control header can have multiple values:


° no-cache

° no-store

° private

° max-age


  • The only value for which the response is actually cached is a max-age,
    which is numeric and non-zero, that is, max-age=x where x > 0.

  • If the Set-Cookie header is present, the response is not cached.


This may be overridden, though, by using the proxy_ignore_headers
directive:
proxy_ignore_headers Set-Cookie;


  • But if doing so, be sure to make the cookie value part of the proxy_cache_key:
    proxy_cache_key "$host$request_uri $cookie_user";

Free download pdf