Score:1

Understanding proxy_cache_bypass $http_cache_control

us flag

According to Nginx's doc on proxy_cache_bypass

Defines conditions under which the response will not be taken from a cache. If at least one value of the string parameters is not empty and is not equal to “0” then the response will not be taken from the cache:

I want the request with the header Cache-Control: no-cache to bypass the Nginx cache and be forwarded to the upstream service. Shall I use the following config?

proxy_cache_bypass $http_cache_control;

I asked because it seems Nginx will bypass the cache whenever the Cache-Control has non-zero value without checking if its content is no-cache. If not, what would be the best way to achieve my goal?

Score:0
jp flag

You are correct. You should use a map to select the correct value to control the cache.

For example:

map $http_cache_control $cache_bypass {
    no-cache   1;
}

proxy_cache_bypass $cache_bypass;

Note that the map block must be placed outside of the server block.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.