0

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?

1 Answer 1

0

One can use nginx map for this. On the http level, define map like this:

map $request_uri $cachecontrol {
    default 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
    "~^/load-custom-js " 'CACHE_HEADER';
}

And in your location block, use the $cachecontrol variable as follows:

add_header Cache-Control $cachecontrol;

You might want to add several map variables for expires, etag and if_modified_since. They would work in the same fashion.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .