james
james

Reputation: 792

Varnish 302 redirects to backend

I have Varnish running on IP Foo with IP Bar as default backend. I visit Varnish on Foo, Apache on Bar returns a 302 and rather than a response coming from Foo, the browser is redirected to Bar, thus missing Varnish altogether.

Is there a fundamental concept of Varnish I am misunderstanding here? I've run Varnish with the exact same VCL on the same server as Apache and it worked fine.

Thanks in advance for any help/tips/pointers :-)

Upvotes: 1

Views: 3232

Answers (1)

ivy
ivy

Reputation: 5559

You're getting a redirect (302) from your back-end. Redirects have to be absolute, and your back-end chooses to use it's own ip/hostname for the url.

You can solve this in many ways:

  • Use the same virtual host on the back-end (e.g. foo.com, which ip points to your varnish but is accepted as a virtual host on your back-end). Your back-end has to be smart enough to use this for redirects.
  • Forward the original ip-adress as a custom HTTP Request Header to the back-end (e.g. see https://serverfault.com/questions/340500/varnish-forward-client-ip-address-to-backend ). Your back-end has to be smart enough to use this for redirects.
  • Rewrite 302 answers in varnish (replace the bar.com part in the Location header with foo.com)

Upvotes: 3

Related Questions