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?


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

upstream backend {
    server fail_timeout=5s max_fails=3;
    server backup;

server {
    listen 80;
    server_name whatevs.com;

    location / {
        proxy_pass http://backend;

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

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

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...

 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.