Skip to content

Instantly share code, notes, and snippets.

@section-io-gists
Created August 14, 2015 01:17
Show Gist options
  • Save section-io-gists/02dba4113b8caf5da473 to your computer and use it in GitHub Desktop.
Save section-io-gists/02dba4113b8caf5da473 to your computer and use it in GitHub Desktop.
Enforce HTTPS with VCL
sub vcl_recv {
//Use req.proto instead of req.http.X-Forwarded-Proto if your varnish server isn't behind a load balancer
if ( req.http.X-Forwarded-Proto !~ "(?i)https") {
//The 750 number is arbitrary, you just need a unique number to check for in the vcl_synth sub
return (synth(750, ""));
}
}
sub vcl_synth {
if (resp.status == 750) {
set resp.status = 301;
set resp.http.Location = "https://" + req.http.host + req.url;
return(deliver);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment