Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2016 20:42
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save danmactough/8ee8d69b7938f3b0dedde47e3cc38324 to your computer and use it in GitHub Desktop.
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
# 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;
Copy link

markudevelop commented Jan 10, 2017

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment