13

I'm having trouble configuring nginx.

I'm using nignx as a reverse proxy. I want to send my all requests to my first server. If the first server is down, I want to send requests to second server.

In short, how can I have a failover solution without load balancing?

13

What you want is an active+passive setup. Here's an example nginx conf snippet to get you going:

upstream backend {
    server 1.2.3.4:80 fail_timeout=5s max_fails=3;
    server 4.5.6.7:80 backup;
}

server {
    listen 80;
    server_name whatevs.com;

    location / {
        proxy_pass http://backend;
    }
}

So, 'normally', all requests will go to host 1.2.3.4. If we get three failures to that box, then 4.5.6.7 will take over.

  • What if you have multiple backups? – Benny Bottema Oct 6 '17 at 12:26
0

Load balancing in nginx is very easy we are just configure server names in upstream scope, where we write server list for load balancing.
nginx support different algorithm for load balancing by default it is round robine, but we configure it with different keys like ip_hash...

http{
 upstream servername{
    ip_hash//for sticky hash
    least_conn//FOR least connection 
    sever localhost:1001;
    sever localhost:1002;
    sever localhost:1003;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.