简体   繁体   English

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

[英]Redirect loop when using Varnish + Nginx (HTTPS)

I am trying to use Varnish and Nginx in a WP site using HTTPS. 我正在尝试使用HTTPS在WP网站中使用Varnish和Nginx。

Everything is working fine with cached files but when Varnish discover something it shouldn't cache, it sends it back to Nginx. 缓存文件一切正常,但是当Varnish发现不应缓存的内容时,会将其发送回Nginx。 At this point, Nginx is sending the HTTPS request to Varnish again causing the infinite loop. 此时,Nginx将HTTPS请求再次发送到Varnish导致无限循环。

I have tried a lot of things and searched over the Internet a lot but nothing has worked so far. 我已经尝试了很多事情,并且在Internet上进行了很多搜索,但是到目前为止没有任何效果。

This is an example of something Varnish is sending back: 这是Varnish发回的示例:

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

And this is the Nginx location block which deals with 433: 这是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;
}

I guess that Varnish is sending with the return(pass) the data back to Nginx, but I don't now how to render that data using another location block. 我想Varnish正在将数据与return(pass)发送回Nginx,但是我现在不知道如何使用另一个location块渲染该数据。

How can I catch in Nginx the request which is coming from Varnish and distinguish between that and the requests which are coming from the regular 433 port? 如何在Nginx中捕获来自Varnish的请求,并区分该请求和来自常规433端口的请求?

Thanks in advance! 提前致谢!

I found the problem: HHVM . 我发现了问题: HHVM

I created another backend without HHVM on Nginx (port 9433) and did the following in Varnish: 我在Nginx(端口9433)上创建了另一个没有HHVM的后端,并在Varnish中执行了以下操作:

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

And then... 接着...

# 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);
}

So when the page is not cached it goes to the port 9433 which doesn't use HHVM. 因此,当不缓存该页面时,它将转到不使用HHVM的端口9433。

Working great now. 现在工作很棒。

这可能是由于hhvm期望通过端口443(https)发出的请求导致重定向到https的请求,该请求再次以清漆结尾。

Try adding: 尝试添加:

fastcgi_param HTTPS on;

to the location block with your fastcgi_pass to php. 到您的fastcgi_pass到php的位置块。 I had this exact problem here: https://serverfault.com/questions/670620/nginx-varnish-hhvm/670857 我在这里遇到了这个确切的问题: https : //serverfault.com/questions/670620/nginx-varnish-hhvm/670857

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM