I have caching enabled on an NGINX proxy.
As I understand it, as long as I'm not ignoring the Cache-Control
header in my proxy configuration (proxy_ignore_headers
), the cache time before expiration can be set from the origin server using Cache-Control
= max-age=XXXX
.
But what would be the default cache time it would keep and use for something like Cache-Control: public
? Is there a way to set a default maximum cache time for these resources?
Best Answer
You'd probably be better off setting or rewriting cache control headers inside Nginx. I have a tutorial on this here, and part one of the tutorial has downloadable config files. The key parts are below
You need headers_more for these to work. Some distributions include this, some don't and you need to build from source - which is pretty easy and is included in my tutorial.
Copied from Tutorial
We use a couple of different techniques to set cache control headers. First off we clear out any existing headers, like the very old Pragma which is not useful any more, clearing Expires headers (which is probably pointless since we set them later), and we clear the Server name for security.
Then we can set the header manually. For image we use quite a long expires time
For pages we keep it shorter – many sites will need this much shorter
In some places we use an alternative format, for convenience.
Example Nginx Configuration
An example Nginx server (with some parts missing like SSL setup)
fastcgi_cache_path /dev/shm/nginxcache levels=1:2 keys_zone=CACHE:50m inactive=1440m; #RAM