Created
August 14, 2015 01:17
-
-
Save section-io-gists/02dba4113b8caf5da473 to your computer and use it in GitHub Desktop.
Enforce HTTPS with VCL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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