![nginx:如何備份/複製 nginx Cache-Control 標頭?](https://rvso.com/image/782621/nginx%EF%BC%9A%E5%A6%82%E4%BD%95%E5%82%99%E4%BB%BD%2F%E8%A4%87%E8%A3%BD%20nginx%20Cache-Control%20%E6%A8%99%E9%A0%AD%EF%BC%9F.png)
後端伺服器設定Cache-Control
HTTP 標頭,但前端可能會操縱它。對於調試來說,查看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回應頭。