I have the proxy pass in nginx config defined as follows:
location / {
proxy_pass http://localhost:3001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Last-Modified $date_gmt;
add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
if_modified_since off;
expires off;
etag off;
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
send_timeout 300s;
}
As you could see, Cache-Control
header is being passed, which tells to cache nothing. But for one of the request which has path /load-custom-js
, I want to return a different cache header which tells browser to cache the response. How could I do this? Would I need to add a new proxy pass block?
One can use nginx
map
for this. On thehttp
level, define map like this:And in your
location
block, use the$cachecontrol
variable as follows:You might want to add several
map
variables forexpires
,etag
andif_modified_since
. They would work in the same fashion.