【问题标题】:Redirect loop when using Varnish + Nginx (HTTPS)使用 Varnish + Nginx (HTTPS) 时的重定向循环
【发布时间】:2015-03-11 19:45:39
【问题描述】:

我正在尝试在使用 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);
}

这是处理 433 的 Nginx 位置块:

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 端口的请求区分开来?

提前致谢!

【问题讨论】:

    标签: wordpress loops nginx https varnish


    【解决方案1】:

    尝试添加:

    fastcgi_param HTTPS on;
    

    使用您的 fastcgi_pass 到 php 的位置块。我在这里遇到了这个确切的问题:https://serverfault.com/questions/670620/nginx-varnish-hhvm/670857

    【讨论】:

      【解决方案2】:

      这可能是由于 hhvm 期望端口 443(https) 上的请求导致重定向到 https 并再次以 varnish 结束。

      【讨论】:

        【解决方案3】:

        我发现了问题: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。

        现在工作得很好。

        【讨论】:

          猜你喜欢
          • 2019-02-02
          • 2015-12-09
          • 1970-01-01
          • 1970-01-01
          • 2021-09-15
          • 2019-08-13
          • 2015-08-30
          • 1970-01-01
          • 2015-01-08
          相关资源
          最近更新 更多