使用 Varnish 更改標頭中的引用者 (Change Referrer in header using Varnish)


問題描述

使用 Varnish 更改標頭中的引用者 (Change Referrer in header using Varnish)

I think this is a possiblity with varnish where you can change the referrer in the header of its users and then serve them the content either from cache or from the server. I want to know how can that be made possible.

I tried this with "req.http.referer" and then "set req.http.referer" in varnish 2.1 on centos 32‑bit machine but it didn't work when i checked the results with the command "varnishtop ‑i TxHeader ‑I Referer".

Anyone got any other ideas better than this?

‑‑‑‑‑

參考解法

方法 1:

At least on Varnish 3.0 the following works as expected. Obviously if the response is served from cache and you are not using the req.http.Referer for hash(), it doesn't matter how you change the referer header.

# Modify Referer header
sub vcl_recv {
  if (req.http.Referer) {
     # Referer was set. Replace foo with bar
     set req.http.Referer = regsub(req.http.Referer,"foo","bar");
  } else {
     # Referer was not set. Set it to something anyway.
     set req.http.Referer = "http://referer.was.empty/";
  }
}

Also note that varnishtop ‑i TxHeader ‑I Referer is case sensitive. If you set req.http.referer then it will not match ‑I Referer even though your HTTP backend will understand the referer: header as well (according to RFC 2612 4.2 message headers are case insensitive).

(by WCOKetola)

參考文件

  1. Change Referrer in header using Varnish (CC BY‑SA 3.0/4.0)

#caching #varnish-vcl #Centos #varnish






相關問題

Heroku 上的頁面緩存技巧? (Page caching trick on Heroku?)

Array of Structs selalu lebih cepat daripada Structs of arrays? (Array of Structs are always faster than Structs of arrays?)

使用 Varnish 更改標頭中的引用者 (Change Referrer in header using Varnish)

清理 ios 中的 uiwebview 緩存 (clean uiwebview cache in ios)

緩存整個表 (Caching the entire table)

過期/緩存控制標頭的問題 (Problem with Expires/Cache-Control Headers)

強制 L1 緩存上的一些數據 (force some data on L1 cache)

Facebook API - 在服務器上緩存響應 (Facebook API - cache response on server)

ASIHTTPRequest 離線模式連接失敗 (ASIHTTPRequest offline mode connection failure)

如果小於 X 天,如何從磁盤讀取文件,如果舊,則重新獲取 html 文件 (How to read a file from the disk if less than X days old, if older, refetch the html file)

當您的應用服務器託管在不同的雲服務上時,如何安全地從 Firebase 託管上的 CDN 緩存中受益 (How to safely benefit from CDN caching on Firebase Hosting when your app's server is hosted on a different Cloud service)

如何使用java處理緩存中的鎖定(ConcurrentHashMap) (How to handle lock in cache (ConcurrentHashMap) using java)







留言討論