Nginx错误502 Bad Gateway是由于许多' Set-Cookie'

时间:2017-09-18 10:08:48

标签: nginx cookies varnish

我在执行 POST 请求时使用Varnish和Nginx部署应用程序时遇到问题。

以下日志来自 varnishlog 命令:

enter image description here

正如大家们所看到的,看起来像Nginx试图多次创建相同的cookie。我检查了我的应用程序,我们没有设置两次相同的cookie值。

我尝试在Nginx上应用以下设置,但没有更改结果:

ClaimsPrincipal

而且我总是得到:

enter image description here

清漆设置:

proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 32k;

Nginx配置:

vcl 4.0;

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

sub vcl_recv {

if (req.method != "GET" && req.method != "HEAD" &&
    req.method != "PUT" && req.method != "POST" &&
    req.method != "TRACE" && req.method != "OPTIONS" &&
    req.method != "DELETE") {
        return(pipe);
} /* Non-RFC2616 or CONNECT which is weird. */

if(req.method == "POST"){
         return (pass);
}

if (req.url ~ "61646D696E2D646576") {
        return (pass);
}

if (req.url ~ "payzen") {
        return (pass);
}

if ((req.url ~ "REFRESH")) {
        set req.url = regsub(req.url, "REFRESH", "");
        return (purge);
}

if (req.http.Cache-Control ~ "no-cache")
{
        return(pass);
}

return(hash);

}

sub vcl_hash {
    hash_data(req.http.X-Forwarded-Proto);
}

sub vcl_backend_response {

if(beresp.status == 500) {
        set beresp.uncacheable = true;
        set beresp.ttl = 120s;
        return (deliver);
}

if(beresp.status == 301 || beresp.status == 302) {
        set beresp.uncacheable = true;
        set beresp.ttl = 120s;
        return (deliver);
}

if (beresp.status >= 200 && beresp.status < 400 && (bereq.method
== "PUT" || bereq.method == "POST" || bereq.method == "DELETE")) {
            ban("obj.http.X-Invalidated-By ~ " + bereq.http.X-Invalidates);
    }

if (!beresp.http.Cache-Control ~ "no-cache") {
       unset beresp.http.set-cookie;
       unset beresp.http.cookie;
}

if (beresp.http.Cache-Control ~ "no-cache") {
        set beresp.uncacheable = true;
}

# IF IT'S SYMFONY DEBUG (DEV) MODE
if (beresp.http.X-Debug-Token) {
        set beresp.uncacheable = true;
}

    return(deliver);

}

sub vcl_deliver {

if (obj.hits > 0){
    set resp.http.X-Varnish-Cache = "HIT";
} else {
    set resp.http.X-Varnish-Cache = "MISS";
}

}

知道问题来自何处?

谢谢! :)

0 个答案:

没有答案