<div dir="ltr"><div dir="ltr"><div>Thank you for your review</div><div><br></div><div>> An obvious workaround is to ensure that such configuration do not </div><div>> allow caching of responses, for example, by using "proxy_cache </div><div>> off;" in such locations.</div><div><br></div><div>If using "proxy_cache off;", all response is not cached.</div><div>The expected behavior is</div><div>    1. when 200 response, it is cached</div><div>    2. when 3xx response, nginx follow the redirect and followed response is cached</div><div>nginx cannot configure whether cache or not cache by response status code.</div><div><br></div><div>> Using "r->cache->valid_sec = 0;" based on the status code, </div><div>> however, looks wrong to me.  First of all, it doesn't actually </div><div>> disable caching, but rather preserves the existing response </div><div>> validity as is - and this may result in more or less arbitrary </div><div>> behaviour.</div><div><br></div><div>client ---> nginx ---> origin</div><div>  |---------->|---------->| req </div><div>  |<----------|<----------| 302 res </div><div>  |---------->|---------->| followed req </div><div>  |<----------|<----------| followed res </div><div><br></div><div>client ---> nginx ---> origin</div><div>  |---------->|---------->| req </div><div>  |              |<----------| 302 res </div><div>  |              |---------->| followed req </div><div>  |<----------|<----------| followed res </div><div><br></div><div>If nginx follow the redirect, it can reduce round-trip time of HTTP request/response sequence between client and nginx</div><div><br></div><div><br></div><div>> Second, it doesn't clear to me if this is something to  </div><div>> be done unconditionally - there can be configuration when caching </div><div>> is desired, despite the fact that $upstream_http_location will not </div><div>> be available.</div><div><br></div><div>I understood your concern. How about adding new directive? </div><div><br></div><div>Syntax: proxy_follow_redirect on | off;</div><div>Default: proxy_follow_redirect off;</div><div>Context: http, server, location</div><div><br></div><div>if (proxy_follow_redirect &&</div><div>    (status == NGX_HTTP_MOVED_PERMANENTLY</div><div>    || status == NGX_HTTP_MOVED_TEMPORARILY</div><div>    || status == NGX_HTTP_SEE_OTHER</div><div>    || status == NGX_HTTP_TEMPORARY_REDIRECT</div><div>    || status == NGX_HTTP_PERMANENT_REDIRECT))</div><div>{</div><div>    r->cache->valid_sec = 0;</div><div>}</div><div><br></div><div>Thanks,</div><div>Sangdeuk</div></div></div>