首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx上的Varnish/Symfony3缓存-在缓存上为0

Nginx上的Varnish/Symfony3缓存-在缓存上为0
EN

Stack Overflow用户
提问于 2016-09-30 04:29:31
回答 1查看 164关注 0票数 0

我已经通过Docker在我的Symfony版本上设置了varnish,但是无法让缓存正常工作。不管我怎么尝试,年龄似乎都保持在0。

读到它可能与设置cookie或可能的expires头有关,但我无论如何也不能弄清楚发生了什么。

响应头部为:

代码语言:javascript
复制
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

请求头部包括:

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
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;
        }
    }
}

更改为以下值不会产生任何影响:

代码语言:javascript
复制
sub vcl_recv {
    unset req.http.Forwarded;
    unset req.http.Cookie;
}

我猜它会是简单的东西,但不能让它工作。感谢您的任何帮助

EN

回答 1

Stack Overflow用户

发布于 2016-11-17 21:54:12

Varnish不缓存设置Cookie的页面,并且在您提供的响应头中有一个Set-Cookie。

要解决此问题,您可以遵循以下两种方法:

  • 继续使用Set-Cookie;
  • Remove Set-Cookie从要缓存的页面中避免缓存那些页面;
  • 或将所有操作与要缓存并通过AJAX调用的页面分开。<代码>H212<代码>F213
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39779438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档