Skip to content

Instantly share code, notes, and snippets.

@denwwer
Last active January 5, 2017 17:09
Show Gist options
  • Save denwwer/ea08a529fdf979e4ca7c3e2b7c51dd12 to your computer and use it in GitHub Desktop.
Save denwwer/ea08a529fdf979e4ca7c3e2b7c51dd12 to your computer and use it in GitHub Desktop.
nginx conf to redirect form http/www to https on AWS ELB
# set DOMAIN_NAME to your domain, example "google.com"
# server {
set $https_redirect 0;
if ($http_host = 'www.DOMAIN_NAME') {
set $https_redirect 1;
}
if ($http_x_forwarded_proto = 'http') {
set $https_redirect 1;
}
if ($http_x_forwarded_proto = '') {
set $https_redirect 1;
}
if ($http_user_agent ~ 'ELB-HealthChecker') {
set $https_redirect 0;
}
if ($https_redirect = 1) {
return 301 https://DOMAIN_NAME$request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment