Nginx – AWS ELB health check failing when trying to force HTTPS through NGINX for the single page application

amazon-elbamazon-web-servicesnginx

I'm trying to force https on my http endpoints using NGINX like so:

server {
    location / {
        root /data/www;
        if ($http_x_forwarded_proto != 'https') {
            rewrite ^ https://$host$request_uri? permanent;
        }
    }
    location /images/ {
        root /data;
    }
}

Note that all im serving from nginx are static files (an HTML file, javascript file, and a coupl

My ELB health check is hitting HTTP:80/. So what I think it's happening, is that ELB tries to ping my server, hits that rewrite, and gets returned a 301? I've seen a lot of answers for ruby and node, but this is just static assets. Help!

Best Answer

Yep, ELB will hit your server via its IP (thus getting the default server block) and anything other than a 2xx request will be handled as a failure.

We use a default server block for ELB to ping:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    location = /status {
      return 200;
      access_log off;
    }
}