0

I have 1 wsgi app that run on 2 nginx box. Let's call the 2 box : ++ box-1.mydomain.com (192.168.1.1) ++ box-2.mydomain.com (192.168.1.2) All will have to able serve 'myapp.mydomain.com'

At each box, the app have to run on 127.0.0.1:5000

My nginx site configuration at box-1

upstream app_by_client {
    server 127.0.0.1:5000 max_fails=3 fail_timeout=10s;
    server box-2.mydomain.com:5001 max_fails=3 fail_timeout=10s;
}

upstream app_by_neigbor {
    server 127.0.0.1:5000 max_fails=3 fail_timeout=10s;
}

server {
    listen 192.168.1.1:80 ;
    server_name myapp.mydomain.com;

    location /api/ {
        proxy_pass http://app_by_client/;
    }
}

server {
    listen 192.168.1.1:5001 ;
    server_name * ;

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

My nginx site configuration at box-2

upstream app_by_client {
    server 127.0.0.1:5000 max_fails=3 fail_timeout=10s;
    server box-1.mydomain.com:5001 max_fails=3 fail_timeout=10s;
}

upstream app_by_neigbor {
    server 127.0.0.1:5000 max_fails=3 fail_timeout=10s;
}

server {
    listen 192.168.1.2:80 ;
    server_name myapp.mydomain.com;

    location /api/ {
        proxy_pass http://app_by_client/;
    }
}

server {
    listen 192.168.1.2:5001 ;
    server_name * ;

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

From the client point of view, the two box is load balanced by DNS roundrobin.

When the two boxes in normal condition, all access is handled correctly

But when (let's say) wsgi app (not nginx) at box-2 died and client hit box-1 and by box-2 upstreamed to box-2 ... request got 'Bad Gateway'.

Kindly please tell me how to fix this problem

Sincerely

-bino-

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.