Skip to content

Instantly share code, notes, and snippets.

@negabaro
Created February 16, 2018 16:43
Show Gist options
  • Save negabaro/7ce72338d07e71569925e752e48be022 to your computer and use it in GitHub Desktop.
Save negabaro/7ce72338d07e71569925e752e48be022 to your computer and use it in GitHub Desktop.
nginx http -> https redirect
# 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