# Load Balancing and High Availability

**URL:** <https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903>\
**Category:** NGINX\
**Created:** [July 23, 2013, 5:00pm UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903 "2013-07-23T17:00:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [July 23, 2013, 5:00pm UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903/1 "2013-07-23T17:00:12Z")

</div>

Hi,

I am a nginx newbie. I have nginx configured as a reverse proxy/load  
balancer in front of a small cluster of Jboss servers. I have configured  
as  
per the tutorials on the web like this one ref:

> **[How To Set Up Nginx Load Balancing | DigitalOcean](https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing)**
>
> This article covers how to set up a simple load balancer on a DigitalOcean droplet with nginx. The tutorial covers setting up a round robin loadbalancer that…

and all works fine with simple round robin load balancing.

My question is, if one of the backend Jboss servers goes down how do I  
stop  
nginx from load balancing requests to the dead application server?

Thanks,  
W

Posted at Nginx Forum:

> **[Load Balancing and High Availability](https://forum.nginx.org/read.php?2,241152,241152#msg-241152)**
>
> Hi, I am a nginx newbie. I have nginx configured as a reverse proxy/load balancer in front of a small cluster of Jboss servers. I have configured as per the tutorials on the web like this one ref:...

---

<div class="post-metadata">

**Author:** ![toriacht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@toriacht](https://www.ruby-forum.com/u/toriacht)\
**Post date:** [July 23, 2013, 5:07pm UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903/2 "2013-07-23T17:07:15Z")

</div>

Hi,

IN answer to my own question I found this…

±-----+  
Max Fails  
According to the default round robin settings, nginx will continue to  
send  
data to the virtual private servers, even if the servers are not  
responding.  
Max fails can automatically prevent this by rendering unresponsive  
servers  
inoperative for a set amount of time. There are two factors associated  
with  
the max fails: max\_fails and fall\_timeout.

Max fails refers to the maximum number of failed attempts to connect to  
a  
server should occur before it is considered inactive.

Fall\_timeout specifies the length of that the server is considered  
inoperative. Once the time expires, new attempts to reach the server  
will  
start up again. The default timeout value is 10 seconds.  
±-----+

Is this the beast way? Is there any gotchas/best practices to be aware  
of?

Thanks  
W

Posted at Nginx Forum:

> **[Re: Load Balancing and High Availability](https://forum.nginx.org/read.php?2,241152,241153#msg-241153)**
>
> Hi, I am a nginx newbie. I have nginx configured as a reverse proxy/load balancer in front of a small cluster of Jboss servers. I have configured as per the tutorials on the web like this one ref:...

---

<div class="post-metadata">

**Author:** ![toriacht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@toriacht](https://www.ruby-forum.com/u/toriacht)\
**Post date:** [July 24, 2013, 12:03am UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903/3 "2013-07-24T00:03:57Z")

</div>

Hi,

Am Dienstag, 23. Juli 2013, 11:06:46 schrieb toriacht:

> Hi,
> 
> IN answer to my own question I found this..
> 
> ±-----+  
> Max Fails  
> Fall\_timeout specifies the length of that the server is considered  
> inoperative. Once the time expires, new attempts to reach the server will  
> start up again. The default timeout value is 10 seconds.  
> ±-----+

this is the way I did it.

I set max\_fails=1 and fail\_timeout in my upstream definition and in my  
location block  
proxy\_next\_upstream http\_502 http\_503 error;

You can use any allowed http status code here

Rgds, Axel

---

<div class="post-metadata">

**Author:** ![toriacht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@toriacht](https://www.ruby-forum.com/u/toriacht)\
**Post date:** [July 23, 2013, 5:16pm UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903/4 "2013-07-23T17:16:36Z")

</div>

Hi Team,

I am newbiw too and i am setting up load balancer with nginx from "  
[How To Set Up Nginx Load Balancing | DigitalOcean](https://www.digitalocean.com/community/articles/how-to-set-up-nginx-load-balancing)"  
but my reuest are not going to the servers which i have configured.

below is the my nginx.conf setup

upstream nitesh {  
server 192.168.1.2;  
server 192.168.1.3;  
server 192.168.1.4;  
}

}

and below is my virtual.conf setup

server {  
listen \*:80;  
server\_name nginx.whmcs.co.in;  
access\_log /var/log/nginx/nginx.access.log;  
error\_log /var/log/nginx/nginx\_error.log debug;  
log\_format upstreamlog ‘[$time\_local] $remote\_addr -  
$remote\_user -  
$server\_name to: $upstream\_addr: $request upstream\_response\_time  
$upstream\_response\_time msec $msec request\_time $request\_time’;  
location / {  
proxy\_pass [http://nitesh](http://nitesh);  
}  
}

but i am not getting the setup page while running website.

my another three server are running with apache.

so update me on the same that i should have to change in that  
configuration.

Posted at Nginx Forum:

> **[Re: Load Balancing and High Availability](https://forum.nginx.org/read.php?2,241152,241154#msg-241154)**
>
> Hi, I am a nginx newbie. I have nginx configured as a reverse proxy/load balancer in front of a small cluster of Jboss servers. I have configured as per the tutorials on the web like this one ref:...

---

<div class="post-metadata">

**Author:** ![toriacht](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ea666f/32.png) [@toriacht](https://www.ruby-forum.com/u/toriacht)\
**Post date:** [July 25, 2013, 12:54am UTC](https://www.ruby-forum.com/t/load-balancing-and-high-availability/235903/5 "2013-07-25T00:54:12Z")

</div>

Hi Axel,

Thank you for the reply. I have pasted some of my nginx.conf file below.  
Can  
you conform if i’m setting proxy\_next\_upstream in correct location  
please?

Also, is there a way to have fail\_timeout increment per fail? i.e if it  
failed once try again in 30 secs as it might be minor issue, then if  
that  
fails try a again in 2 mins, then 4 mins etc?

user nginx;  
worker\_processes 1;

error\_log /var/log/nginx/error.log;  
#error\_log /var/log/nginx/error.log notice;  
#error\_log /var/log/nginx/error.log info;

pid /run/nginx.pid;

events {  
worker\_connections 1024;  
}

http {  
include /etc/nginx/mime.types;  
default\_type application/octet-stream;

```
log_format main '$remote_addr - $remote_user [$time_local] 

```

“$request”  
’  
'$status $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#set headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Queue-Start "t=${msec}000";

```

# switch to next upstream server in these scenarios

```
proxy_next_upstream http_502 http_503 error;

# load balancer
# ip_hash provides sticky session
upstream balancer {
    ip_hash;
    server 127.0.0.1:8180 max_fails=1 fail_timeout=2000s;
    server 127.0.0.1:8280 max_fails=1 fail_timeout=2000s;

}
#gzip on;

# Load modular configuration files from the /etc/nginx/conf.d

```

directory.  
# See [Core functionality](http://nginx.org/en/docs/ngx_core_module.html#include)  
# for more information.  
include /etc/nginx/conf.d/\*.conf;

```
server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    access_log /var/log/nginx/host.access.log main;

```

location / {  
root /usr/share/nginx/html;  
index index.html index.htm;  
}

```
    #rules for rest
    location /rest/ {
            #proxy_pass http://127.0.0.1:8080/MyApp/rest/;
            proxy_pass http://balancer/MyApp/rest/;
     }

```

* * *

* * *

Many thanks

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,241152,241211#msg-241211](http://forum.nginx.org/read.php?2,241152,241211#msg-241211)
