Amazon's Elastic Load Balancer (ELB) distributes requests to healthy instances that have been assigned to it. It does not restart or modify those instances (or their number). It determines 'healthy' instances via a health check - typically polling a given location.
What you are asking for is to 'maintain 1 healthy instance' - that is an auto scaling task. Auto scaling will allow you to define a group of instances (typically including an AMI to launch, the instance type, one or more availability zones to launch the instances in, and the number of instances to maintain (minimum/maximum)), as well as policies by which to scale up and down with. An autoscaling policy returns an ARN (Amazon Resource Name - a reference to a resource).
Once you have your auto scaling group setup, all you need to do is trigger your scaling policies when an instance becomes unhealthy. If you look closely at the health check that you setup with ELB, you will notice that you can setup an alarm - and that alarm is actually a Cloudwatch alarm.
You can setup your own Cloudwatch alarms, or set them up through ELB's health check - just specify the --alarm-actions
to trigger the auto-scaling ARN when your unhealthy node criteria is met.
ELB isn't technically required in this setup - auto scaling will do the job on its own. What ELB does do for you is provide a DNS address you can access your instance(s) by (and also some sort of error message when a backend is unavailable). (With auto scaling on its own, you would need to re-associate your elastic IP with the new instance when it launches (which can be scripted)).
Finally, just to clarify:
CloudFlare is not an AWS service - it is a CDN (and is somewhat well known for mitigating DDoS attacks). Amazon's equivalent service is CloudFront - you don't need either of them for restarting instances. What you do need is CloudWatch - Amazon's monitoring service). The free tier does cover both Cloudwatch and a few alarms.
You could run something like this:
domain1.com domain2.com domain3.com
\ | /
\ | /
\ | /
\ | /
\ | /
\ | /
\_______|_______/
|
ngix (static pages from local storage, 3 IP addresses, SSL termination)
|
|
ELB (optional)
|
|
-----------------------
| | |
V V V
php php php
It would be a little bit cheaper, as 1 EC2 reserved small instance + 1 ELB is cheaper than 3 ELB.
You could be even cheaper if you could ditch ELB and just use normal DNS round robin (but you'll loose some ELB features like automatic failover).
Latency on serving static pages would not be affected by load on php-serving instances.
PHP serving would not compete for RAM with static pages OS cache.
You could even use apache mod_php instead of php-fpm is you don't need user separation between processes - it should be somewhat faster.
It would be cheaper to add more pages to serve (add one more IP instead of one more ELB).
But it also has some drawbacks:
Best Answer
Here are two ways to solve this;
First option is to add another health check on the host that validates the health and returns HTTP 200s to the ELB if the logic says that you want to keep the host online. The logic there is, of course, up to you. The disadvantage here would be that if App 2 deployed successfully on some hosts all hosts would still be 'healthy' and receiving traffic.
Another option is to use an additional ELB for each application. You can point several ELBs to the same backend EC2 instances and the cost is pretty minor to do so. That way you can health check per application and drop hosts with issues at a per-application level rather than an all-or-nothing approach.
Edit: Please note this is an older answer and is specific to ELB not ALB. ALB supports separate targets on one host natively.