nginx:如何備份/複製 nginx Cache-Control 標頭?

nginx:如何備份/複製 nginx Cache-Control 標頭?

後端伺服器設定Cache-ControlHTTP 標頭,但前端可能會操縱它。對於調試來說,查看Cache-Control後端設定的 HTTP 標頭會很有用。因此想知道,是否可以在後端伺服器上設定X-包含與 相同值的自訂 () 標頭Cache-Control

我已經嘗試過以下操作:

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

但這沒有用。未添加標頭。

這不是 的問題more_set_headers。以下工作有效:

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

新增了標題。但這只是一個簡單的測試,看看是否可以設定標頭,顯然沒有什麼用處。

答案1

您正在尋找$sent_http_cache_control變數。這將包含響應的Cache-Control值,因此:

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

答案2

這些$http_變數包含來自 HTTP 請求的 HTTP 標頭,如 nginx 所示文件

不知道有沒有辦法在nginx引用HTTP回應頭。

相關內容