I've configured Nginx to cache all responses from an upstream server that always returns Cache-Control: public, max-age=1
but nginx seems to cache the response for 2 seconds. How come?
More specifically, my upstream server is a simple Express.js (node) app that returns the current time:
app.get('/', function (req, res) {
res.setHeader('Cache-Control', 'public, max-age=1');
res.send((new Date()).toISOString());
});
And this is the relevant nginx config:
http {
proxy_cache_path /data levels=1:2 keys_zone=zuul:10m max_size=10g;
...
server {
location / {
proxy_cache zuul;
proxy_pass http://zuul;
proxy_cache_use_stale updating;
proxy_cache_background_update on;
}
listen 0.0.0.0:80 default_server;
}
}
I then curl http://localhost
in a loop and expect to see the response (containing the timestamp as node.js sees it) change every second. Instead of it changes every two seconds. It's as if Nginx is unwilling to cache responses for less than two seconds, not respecting the max-age
returned by the upstream.
How can I convince Nginx to cache responses