Can Nginx only cache reponse body while excluding some response headers?

Francis Daly francis at daoine.org
Fri Dec 7 23:14:24 UTC 2018


On Sat, Dec 08, 2018 at 06:40:52AM +0800, yf chu wrote:

Hi there,

> A request is sent from client to nginx, if it did not hit the cache, I hope nginx only caches the response body returned by upstream and send the headers and response body returned by upstream to client.
> If the request hit the cache, I hope nginx can generate new headers and send them with the cached response body to client.   

Ok.

What new headers do you want nginx to generate? (And how would you
configure nginx to do so?)

I suspect that stock nginx does not do this; but maybe something could
be done with one of the embedded languages.

I wonder -- would changing the upstream to send an X-Accel-Redirect
header, along with its for-this-response headers, be useful here? If
so, nginx could potentially send the same local file contents, with
fresh-from-upstream headers each time.

That could avoid doing anything with the nginx cache; and all of the
"header generation" logic would be on the upstream server.

And it might be simpler than patching nginx, if that is what is necessary.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list