使用Varnish + Nginx(HTTPS)时重定向循环

时间:2015-01-13 18:39:52

标签: wordpress loops nginx https varnish

我正在尝试使用HTTPS在WP站点中使用Varnish和Nginx。

使用缓存文件一切正常,但是当Varnish发现它不应该缓存的东西时,它会将它发送回Nginx。 此时,Nginx再次向Varnish发送HTTPS请求,导致无限循环。

我已经尝试了很多东西并且在互联网上搜索了很多东西,但到目前为止还没有任何工作。

这是Varnish送回的一个例子:

if (req.url ~ "/wp-(login|admin|cron)") {
        # Don't cache, pass to backend
        return (pass);
}

这是Nginx位置块,处理433:

location / {
    # Send request to varnish
    proxy_pass  http://127.0.0.1:8888;
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Port 443;
    proxy_set_header Host $host;
}

我想Varnish正在将return(pass)数据发送回Nginx,但我现在不知道如何使用其他位置块来渲染数据。

如何在Nginx中捕获来自Varnish的请求,并将其与来自常规433端口的请求区分开来?

提前致谢!

3 个答案:

答案 0 :(得分:1)

我发现了问题: HHVM

我在Nginx(端口9433)上创建了另一个没有HHVM的后端,并在Varnish中执行了以下操作:

backend no_hhvm {
   .host = "127.0.0.1";
   .port = "9433";
}

然后......

# Either the admin pages or the login
if (req.url ~ "/wp-(login|admin|cron)") {
        # Don't cache, pass to backend
        set req.backend = no_hhvm;
        return (pass);
}

因此,当页面未缓存时,它会转到不使用HHVM的端口9433。

现在工作得很好。

答案 1 :(得分:1)

这可能是因为hhvm期望请求超过端口443(https)导致重定向到https,最终再次以清漆结束。

答案 2 :(得分:0)

尝试添加:

fastcgi_param HTTPS on;
使用fastcgi_pass到php的位置块

。我在这里遇到了这个问题:https://serverfault.com/questions/670620/nginx-varnish-hhvm/670857