You can setup a load balancing pool where a server not responding within a timeframe is removed. Using sticky sessions using ip_hash where the same ip-address goes back to the same server. Useful for maintaining sessions if sessioninformation is not shared across servers. nginx have a well documented page with the various options.
http {
upstream my_pool {
ip_hash;
server 1.2.3.4 weight=3 max_fails=3 fail_timeout=20s;
server 1.2.3.5 weight=4 max_fails=3 fail_timeout=20s;
server 1.2.3.6 weight=3 max_fails=3 fail_timeout=20s;
}
server {
listen 80 ;
server_name domain.org www.domain.org;
location / {
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://my_pool;
}
}
}