I want to add a header (Cache-control
) in nginx only if it is not set.
I need to increase cache time in some case via the header in nginx.
I want to add a header (Cache-control
) in nginx only if it is not set.
I need to increase cache time in some case via the header in nginx.
You can use
map
to populate a variable$cachecontrol
. If$http_cache_control
(the header from the client) is empty, set a custom value. Otherwise (default) reuse the value from the client.Afterwards you can use that variable to send the upstream header.
For the follow-up question from jmcollin92, I wrote the following in SO Documentation, now transcribed here.
X-Request-ID
nginx
Reverse proxies can detect if a client provides a X-Request-ID header, and pass it on to the backend server. If no such header is provided, it can provide a random value.
The code above stores the Request ID in the variable
$reqid
from where it can be subsequently used in logs.It should also be passed on to the backend services