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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

yf chu

We all know that the cache feature in Nginx will cache all response content generated by upstream server. But I wonder whether there is a solution that only the response body is cached by Nginx while some response headers should not be cached and should be sent to client directly .I know that Nginx provides some cache-bypassing directives such as "proxy_no_cache","proxy_cache_bypass". These directives are not suitable for me as the hits pecentage will drop significantly if these directives are configured. 



 



 


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

Francis Daly
On Sun, Dec 02, 2018 at 06:29:33PM +0800, yf chu wrote:

Hi there,

> We all know that the cache feature in Nginx will cache all response content generated by upstream server. But I wonder whether there is a solution that only the response body is cached by Nginx while some response headers should not be cached and should be sent to client directly .

I'm afraid I don't understand what exactly you are asking.

Could you give more details, or an example?

Such as:

request from client to nginx; not in cache, so nginx asks upstream which
returns headers+body. What do you want nginx to store in the cache,
and what should nginx send to the client?

same request from client to nginx; it is in the cache. What should nginx
send to the client?

The answer to that might make your question clearer.

Thanks,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

yf chu
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.   






At 2018-12-08 06:23:54, "Francis Daly" <[hidden email]> wrote: >On Sun, Dec 02, 2018 at 06:29:33PM +0800, yf chu wrote: > >Hi there, > >> We all know that the cache feature in Nginx will cache all response content generated by upstream server. But I wonder whether there is a solution that only the response body is cached by Nginx while some response headers should not be cached and should be sent to client directly . > >I'm afraid I don't understand what exactly you are asking. > >Could you give more details, or an example? > >Such as: > >request from client to nginx; not in cache, so nginx asks upstream which >returns headers+body. What do you want nginx to store in the cache, >and what should nginx send to the client? > >same request from client to nginx; it is in the cache. What should nginx >send to the client? > >The answer to that might make your question clearer. > >Thanks, > > f >-- >Francis Daly [hidden email] >_______________________________________________ >nginx mailing list >[hidden email] >http://mailman.nginx.org/mailman/listinfo/nginx


 


_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

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

Francis Daly
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        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx