Created
April 28, 2016 20:42
-
-
Save danmactough/8ee8d69b7938f3b0dedde47e3cc38324 to your computer and use it in GitHub Desktop.
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
container_commands: | |
10redirect: | |
command: perl -0777 -pe 's#(listen 8080;\n)#$1\n if (\$request_uri = "/health") {\n set \$redirectFlag N;\n }\n\n if (\$http_x_forwarded_proto != "https") {\n set \$redirectFlag "\${redirectFlag}Y";\n }\n\n if (\$redirectFlag = "Y") {\n return 301 https://\$host\$request_uri;\n }#igms' -i /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf |
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
# the container command will insert this snippet immediately after | |
# listen 8080; | |
# We don't want to redirect health check traffic from the Elastic Load Balancer | |
# or it will think our app is not healthy | |
if ($request_uri = "/health") { | |
set $redirectFlag N; | |
} | |
# And nginx doesn't allow nested or compound conditionals | |
# So we build up this "redirectFlag" variable as a string | |
if ($http_x_forwarded_proto != "https") { | |
set $redirectFlag "${redirectFlag}Y"; | |
} | |
# And now we know: if the value is exactly "Y", it is safe to redirect | |
# If the traffic is from the load balancer, which we don't want to redirect, | |
# the value will be "NY", which will not match | |
if ($redirectFlag = "Y") { | |
return 301 https://$host$request_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much helped me a lot!
and the health check oh yeah that's a nice one can't find that over the internet :)