Advertisement
loudmouthman

Handling rewrites in Varnish http to https

Jan 19th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.00 KB | None | 0 0
  1. sub vcl_recv{
  2. if (req.http.host == "exampledomain.com") {
  3.     set req.http.Location = "https://www.exampledomain.com" + req.url;
  4.           error 750 "Permanently moved";
  5.   }
  6. if (  (req.http.host ~ "(?i)www.exampledomain.com") && (req.http.X-Forwarded-Proto !~ "(?i)https")     ) {
  7.         set req.http.x-redir-url = "https://www.exampledomain.com" + req.url;
  8.         error 751 req.http.x-redir-url;
  9.     }
  10. if (  (req.http.host ~ "(?i)www.exampledomain.com") && (req.http.X-Forwarded-Port == "80")     ) {
  11.         set req.http.x-redir-url = "https://www.exampledomain.com" + req.url;
  12.         error 751 req.http.x-redir-url;
  13.     }
  14. }
  15.  
  16. sub vcl_error {
  17.         if (obj.status == 750) {
  18.                 set obj.http.location = req.http.Location;
  19.                 set obj.status = 301;
  20.                 return (deliver);
  21.         }
  22.  
  23.         if (obj.status == 751) {
  24.                 set obj.http.Location = obj.response;
  25.                 set obj.status = 302;
  26.                 return (deliver);
  27.         }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement