Created
February 16, 2018 16:43
-
-
Save negabaro/7ce72338d07e71569925e752e48be022 to your computer and use it in GitHub Desktop.
nginx http -> https redirect
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
# http -> https redirect | |
set $check_redirect ""; | |
set $check_domain ""; | |
if ($http_host ~ xx\.xx$) { | |
set $check_domain "on"; | |
} | |
if ($http_host ~ yy\.yy$) { | |
set $check_domain "on"; | |
} | |
if ($check_domain = "on") { | |
set $check_redirect "${check_redirect}1"; | |
} | |
if ($http_x_forwarded_proto != "https") { | |
set $check_redirect "${check_redirect}_2"; | |
} | |
if ($http_user_agent !~ ^ELB-HealthChecker) { | |
set $check_redirect "${check_redirect}_3"; | |
} | |
if ($check_redirect = "1_2_3") { | |
rewrite ^/(.*)?$ https://$http_host/$1 permanent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment