Daniele Grillo
Daniele Grillo

Reputation: 1023

Nginx upstream active passive

I have in my nginx configuration an upstream with 3 server. I need to set this configuration in order to priority... If my server1 is up all connection go to him. If my server1 is down all connection go to server 2 If my server 2 is down all connection go to server 3.

Is possible this?

I have set ip_hash directive and set the directive backup to my server2 and 3 in my upstream. But this seem that don't work. Have you any suggest?

Is possibile too add a condition that in my server1 is 404 error go to next server in order? Thank you

This is my nginx configuration.. but when IP 192.168.10.1 nginx go in round-robin mode to 192.168.10.2 and 192.168.10.3 and this is not good for my mail webserver

upstream mail {
        #ip_hash;
        server 192.168.10.1:80;
        server 192.168.10.2:80 backup;
        server 192.168.10.3:80 backup;
        #health_check;
    }




server {
    listen       443 ssl;
    server_name  mail.test.com;
    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header        X-Forwarded-Proto $scheme;
        add_header  Front-End-Https   on;
        proxy_pass http://mail;
    }
}

Upvotes: 0

Views: 4217

Answers (2)

fens
fens

Reputation: 31

Yes, it is possible, you need 2 upstream section and 1 additional server section such as:

upstream backend {
    server server1.net;
    server 127.0.0.1:8010 backup;
}

upstream fallback {
    server server2.net;
    server server3.net backup;
}

server {
    listen 127.0.0.1:8010;
    location / {
        proxy_pass http://fallback;
        proxy_next_upstream invalid_header http_500 http_502 http_504 http_403;
    }
}

I hope this solution will help you.

Upvotes: 2

Harshad Yeola
Harshad Yeola

Reputation: 1190

You can mark servers as backup using the "backup" directive when setting up the upstream. These servers are used when all of the normal upstream servers stop responding to requests.

upstream backend {
      server 1.0.1.1;
      server 1.0.1.2 backup;
      server 1.0.1.3 backup;
}  

Upvotes: -1

Related Questions