Score:0

nginx: How to backup / duplicate nginx Cache-Control header?

ao flag

The backend server sets the Cache-Control HTTP header but the frontend might manipulate it. For debugging it would be useful to see the Cache-Control HTTP header as the backend had set it. Hence wondering, it it possible on the backend server to set custom (X-) header that contains the same value as Cache-Control?

I tried the following already:

more_set_headers "X-Backend-Cache-Control: $http_cache_control";

But that didn't work. No header has been added.

It's not an issue with more_set_headers. The following worked:

more_set_headers "X-Backend-Cache-Control: test";

A header was added. But that was just a simple test to see headers can be set at all and not useful obviously.

Score:1
cn flag

You're looking for the $sent_http_cache_control variable. This will contain the response's Cache-Control value, so:

more_set_headers "X-Backend-Cache-Control: $sent_http_cache_control";
adrelanos avatar
ao flag
Did you test this? Unfortunately this also does not work for me.
cn flag
@adrelanos Yes. It should be applied on your front-end server, e.g. alongside `proxy_pass`.
adrelanos avatar
ao flag
I was setting it in the backend. That didn't work. Setting it in the frontend worked. I was hoping it's possible to set this setting in the backend.
Score:0
us flag

The $http_ variables contain HTTP headers from the HTTP request, as shown in nginx documentation.

I don't know if there is a way to refer to HTTP response headers in nginx.

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.