Welcome! Log In Create A New Profile

Advanced

Re: Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Maxim Dounin
March 12, 2019 10:12PM
Hello!

On Tue, Mar 12, 2019 at 09:42:22PM +0100, Manuel wrote:

> > From practical point of view, however, these should be enough to
> > return correct responses to clients. What is stored in the cache
> > file is irrelevant.
>
> Well, the expires header is in the cached file, and that was the problem.
> The expires was not 30d but some 1.x days.
> And so the cache will request upstream to early, because upstream
> returned Cache-Control: max-age=126195
>
> I want to cache the upstream resource for 30d
> regardless of the returned cache headers from upstream.

As long as a particular header is ignored using the
"proxy_ignore_header" directive, it doesn't matter what it
contains in the response returned by upstream server and/or in the
cache file, nginx will not use the header to determine response
validity time. Instead, it will use other headers which are not
ignored (if any), or will determine cache validity based on
proxy_cache_valid directives. The resulting validity time is
stored in the binary cache header which comes before response
headers in the cache file.

Note well that cache validity time is determined when a response
is stored into cache, so changing proxy_cache_valid in the
configuration won't change the validity times of previously cached
responses. A response needs to be re-cached for proxy_cache_valid
changes to be applied.

> My solution now is a two step approach:
> step one: check cache, if the resource is expired
> or not cached, nginx calls itself to get the resource.
> Step two: call upstream and modify the expires
> header to 30d. Return response to the cache.
> Cache is now happy with an expires 30d header :-)

Well, using double proxying will certainly work too, but in this
particular case it is not needed.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Manuel March 11, 2019 08:00PM

Re: Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Maxim Dounin March 12, 2019 08:44AM

Re: Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Manuel March 12, 2019 04:44PM

Re: Possible to modify response headers from a proxied request before the response is written do the cache? (modified headers should be written to disk)

Maxim Dounin March 12, 2019 10:12PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 60
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready