Skip to content

Instantly share code, notes, and snippets.

@foxted
Created April 19, 2018 10:35
Show Gist options
  • Save foxted/3a2e57f23a6720000406841d5fd2f75e to your computer and use it in GitHub Desktop.
Save foxted/3a2e57f23a6720000406841d5fd2f75e to your computer and use it in GitHub Desktop.
Force https on EC2 behind ALB except Healthchecks
server {
# If traffic is http
if ($http_x_forwarded_proto != 'https') {
set $force_https "A";
}
if ($http_user_agent ~ 'ELB-HealthChecker/2.0') {
set $force_https "${force_https}B";
}
if ($force_https = 'A') {
return 301 https://$host$request_uri;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment