Using one ELB per app is the way to go here.
First, you may need them anyway if each application is on it's own domain and you need to support SSL. Amazon ELBs currently only allow one SSL certificate for each domain, requiring separate ELBs for each SSL-enabled domain. (Wildcard SSL certifications being an exception).
The challenge here is that ELB health checks cannot currently be directed to a particular virtual domain hosted on an EC2 instance. (No "Host:" header is sent). ELB health pings always go to the default domain, as if the you had loaded the IP address for the EC2 instance in your browser. So some glue is required to recieve the health checks on the default domain and then reply with health status of a particular application.
Here is a working example configuration that could be added to an Nginx server
directive. It would be installed
on each of the EC2 instances being load balanced.
# This goes in the `server` block noted by 'default_server', often /etc/nginx/sites-enabled/default
# All AWS Health Checks from the ELBs arrive at the default server.
# Forward these requests on the appropriate configuration on this host.
location /health-check/ {
rewrite ^/health-check/(?<domain>[a-zA-Z0-9\.]+) /api/v1/status break;
# Lie about incoming protocol, to avoid the backend issuing a 301 redirect from insecure->secure,
# which would not be considered successful.
proxy_set_header X-Forwarded-Proto 'https';
proxy_set_header "Host" $domain;
proxy_pass http://127.0.0.1;
}
In the In the "Health Check" setting of of the ELB for "first-application.com", you would select "HTTP" and Port 80 and enter a path like:
/health-check/first-application.com
With the above Nginx configuration running on the host, the request would be received on the default domain
and proxy the response from the Nginx configuration on the same host for https://first-application.com/api/v1/status
With this approach there is no per-app configuration in Nginx. As long as each app has a unique domain name, you just need to make sure you set up an ELB for each app appropriately.