-set $redirect 0;
-if ( $scheme = http ) { set $redirect 1; }
+set $_https_only 0;
+if ( $scheme = http ) { set $_https_only 1; }
# Live is behind a load balancer which do only http queries
-if ($http_x_forwarded_proto = "https") { set $redirect 0; }
-if ( $redirect = 1 ) { return 301 https://$host$request_uri; }
+if ($http_x_forwarded_proto = "https") { set $_https_only 0; }
+
+if ( $https_only = "") { set $https_only ""; }
+if ( $https_only != "") { set $_https_only $https_only; }
+
+if ( $_https_only = 1 ) { return 301 https://$host$request_uri; }