簡體   English   中英

Nginx上的Varnish / Symfony3緩存-緩存前為0

[英]Varnish/Symfony3 Cache on Nginx - Ago 0 on caching

我已經在我的Symfony構建中通過Docker設置了清漆,但是無法使緩存正常工作。 不管我嘗試什么,年齡似乎都保持在0。

通過閱讀有關它的信息,可能與設置cookie或使標頭過期有關,但是我無法終生弄清正在發生的事情。

響應頭是:

Age:0
Cache-Control:max-age=64000, public, s-maxage=64000
Connection:keep-alive
Content-Type:text/html; charset=UTF-8
Date:Thu, 29 Sep 2016 20:21:43 GMT
ETag:"cb3ed8f6672c4be1148c4f7d12c20789"
Server:nginx
Set-Cookie:device_view=full; expires=Sat, 29-Oct-2016 20:21:43 GMT; Max-Age=2592000; path=/; HttpOnly
Transfer-Encoding:chunked
Vary:Accept-Encoding, Accept-Language
Via:1.1 varnish-v4
X-Cache-Debug:1
X-Cache-Debug:1
X-Debug-Token:503eda
X-Debug-Token-Link:http://192.168.99.100/app_dev.php/_profiler/503eda
X-Powered-By:PHP/7.0.11
X-Varnish:65542

請求標頭為:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:keep-alive
Cookie:customcookie=1; _gat=1; PHPSESSID=1fd8cd59c8d8d0185310ec0cdb06fce7; _ga=GA1.1.706323429.1474891952; hl=en; device_view=full
Host:192.168.99.100
Pragma:no-cache
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36

當前的VCL文件:

vcl 4.0;

backend default {
    .host = "192.168.99.100";
    .port = "8080";
}

sub vcl_recv {
    unset req.http.Forwarded;

    if (req.http.X-Forwarded-Proto == "https" ) {
        set req.http.X-Forwarded-Port = "443";
    } else {
        set req.http.X-Forwarded-Port = "80";
    }

    // Remove all cookies except the session ID.
    if (req.http.Cookie) {
        set req.http.Cookie = ";" + req.http.Cookie;
        set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
        set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
        set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
        set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

        if (req.http.Cookie == "") {
            // If there are no more cookies, remove the header to get page cached.
            unset req.http.Cookie;
        }
    }
}

更改為以下內容無效:

sub vcl_recv {
    unset req.http.Forwarded;
    unset req.http.Cookie;
}

我猜這將是簡單的事情,但無法使其正常工作。 任何幫助表示贊賞

Varnish不會緩存設置cookie的頁面,並且在您提供的響應標頭中有Set-Cookie

要解決此問題,您可以采取兩種方法:

  • 繼續避免使用Set-Cookie 緩存那些頁面;
  • 從要緩存的頁面中刪除所有Set-Cookie
  • 或者將所有操作與要緩存的頁面分開,然后通過AJAX調用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM