Welcome! Log In Create A New Profile

Advanced

[PATCH] reset r->cache->valid_sec for following the redirect

Sangdeuk Kwon
May 16, 2019 12:30AM
Thank you for your review

> An obvious workaround is to ensure that such configuration do not
> allow caching of responses, for example, by using "proxy_cache
> off;" in such locations.

If using "proxy_cache off;", all response is not cached.
The expected behavior is
1. when 200 response, it is cached
2. when 3xx response, nginx follow the redirect and followed response
is cached
nginx cannot configure whether cache or not cache by response status code.

> Using "r->cache->valid_sec = 0;" based on the status code,
> however, looks wrong to me. First of all, it doesn't actually
> disable caching, but rather preserves the existing response
> validity as is - and this may result in more or less arbitrary
> behaviour.

client ---> nginx ---> origin
|---------->|---------->| req
|<----------|<----------| 302 res
|---------->|---------->| followed req
|<----------|<----------| followed res

client ---> nginx ---> origin
|---------->|---------->| req
| |<----------| 302 res
| |---------->| followed req
|<----------|<----------| followed res

If nginx follow the redirect, it can reduce round-trip time of HTTP
request/response sequence between client and nginx


> Second, it doesn't clear to me if this is something to
> be done unconditionally - there can be configuration when caching
> is desired, despite the fact that $upstream_http_location will not
> be available.

I understood your concern. How about adding new directive?

Syntax: proxy_follow_redirect on | off;
Default: proxy_follow_redirect off;
Context: http, server, location

if (proxy_follow_redirect &&
(status == NGX_HTTP_MOVED_PERMANENTLY
|| status == NGX_HTTP_MOVED_TEMPORARILY
|| status == NGX_HTTP_SEE_OTHER
|| status == NGX_HTTP_TEMPORARY_REDIRECT
|| status == NGX_HTTP_PERMANENT_REDIRECT))
{
r->cache->valid_sec = 0;
}

Thanks,
Sangdeuk
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] reset r->cache->valid_sec for following the redirect

Sangdeuk Kwon 153 May 16, 2019 12:30AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 78
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