I installed varnish as HTTP accelerator in front of my apache server. Some of my sites can be accessed only via https. When accessed via http, clients get redirected to https (the redirection is done in the virtual host definition).
After varnish's installation, I wanted to move the redirection under varnish. In order to redirect browsers using varnish, edit /etc/varnish/default.vcl and add the following:

sub vcl_recv {
if (req.http.host ~ "webmail\.glennie\.fr" || req.http.host ~ "nagios\.glennie.fr" || req.http.host ~ "stats\.glennie\.fr") {
       set req.http.x-host = req.http.host;
       set req.http.x-url = req.url;
       return(synth(750, "https://" + req.http.x-host + req.http.x-url));

sub vcl_synth {
    if (resp.status == 750) {
      set resp.http.Location = "https://" + req.http.x-host + req.http.x-url;
      set resp.status = 301 ;


Post your comment

Simple HTML markup is allowed.