Why is Varnish redirecting as 301?

2019-09-17 14:24发布

I have been deploying a mediawiki docker container (appscontainer/mediawiki) based on Apache2 on a VPS, and I put a fresh install of Varnish on top of it, to be able to proxied different subdomains to the proper applications on the same server.

My current default.vcl configuration file look like the following:

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

backend wikimedia {
 .host = "localhost";
 .port = "8080";
}

sub vcl_recv {
  if(req.http.host == "wiki.virtual-assembly.org") {
    set req.backend_hint = wikimedia;
  }

  set req.backend_hint = default;
}

My issue is that when I request the URL http://wiki.virtual-assembly.org, I got redirected via a 301 to the IP adress of the server on port 8080 (port on which the apache2 instance is listening).

Is there a way to tell Varnish to keep the location to be http://wiki.virtual-assembly.org, or is it an apache2 misconfiguration ?

Thanks in advance,

PS: I know my two backends are equivalent, I will change the default in the future when I will have deployed more apps.

1条回答
The star\"
2楼-- · 2019-09-17 14:57

Shot in the dark answer. Do you still get a 301 if you put the default backend_req into an else statement instead of outside the if?

查看更多
登录 后发表回答