[英]Nginx as reverse proxy and cache if backend sends a header
我想從應用程序的邏輯而不是從nginx的配置文件來控制緩存,並且不要讓請求到達apache / php。
http://wiki.nginx.org/HttpCoreModule#Variables提供以下內容:
$sent_http_HEADER
The value of the HTTP response header HEADER when converted to lowercase and
with 'dashes' converted to 'underscores',
e.g. $sent_http_cache_control, $sent_http_content_type...;
$cookie_COOKIE
The value of the cookie COOKIE;
如果將其與if塊結合使用,則可以執行以下操作:
if ($sent_http_your_added_header = "") {
proxy_cache your_cache_zone;
}
if ($cookie_BYPASS = "1") {
proxy_bypass $cookie_BYPASS;
}
注意:如果您的BYPASS Cookie的值是1或0,您實際上可能會忘記if並僅使用$ cookie_BYPASS,請參閱http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_bypass
就緩存時間而言,如http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_valid所述 ,nginx會響應“ X-Accel-Expires”,“ Expires”和“ Cache-Control”標頭(除非您通過proxy_ignore_headers指令告訴它不這樣做)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.