SSL Redirection and Basic Auth in Varnish
Varnish has proven itself to be quite brilliant and blindingly fast when it comes to caching. Quite recently I was in a situation where varnish was used as a frontend with nginx serving out a webapp and node serving out API services. The requirements for varnish were to honour cache headers churned out by the application, redirect all incoming requests to https and have basic auth in place. Now varnish doesn't ssl redirect out of the box nor does it have a straight forward way of putting basic auth in place. In order to handle SSL Redirection, this is the most promising solution I found. In the vcl_recv segment, right at the beginning put the following condition sub vcl_recv { # SSL redirection if ( req.http.host ~ "^(?i)(www\.)?.*(\.<domain>)" && req.http.X-Forwarded-Proto !~ "(?i)https" ) { set req.http.x-Redir-Url = "https://" + req.http.host + req.url; error 750 req.http.x-Redir-Url; } ... return (loo...