Upstream Fallback if Backends can´t be reached

kperas nginx-forum at nginx.us
Thu Dec 15 16:10:50 UTC 2011


Hi Forum, i´m new to nginx and trying to realize the following. I want
to Loadbalance two Backends and have nginx to be the ssl Proxy. That
works so far. 
I want nginx to rewrite a particular url to something else. That works
too.
But now i want to send the Clients to a maintenance site, if both
Backends fail, and i´m fighting like crazy here, but can´t get it to
work. Maybe you can give me some advice, here is me config:

user  nginx;
worker_processes  1;

#error_log  logs/error.log;
error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
  upstream online {
       healthcheck_enabled;
       healthcheck_delay 5000;
       healthcheck_timeout 5000;
       healthcheck_failcount 1;
       server 10.194.1.10:8080  max_fails=2  fail_timeout=2s weight=2;
       server 10.194.1.108:8080  max_fails=2  fail_timeout=2s weight=2;
       server 10.194.100.50:8080 weight=5; ##Fallback
       sticky;
       ip_hash;
  }
  upstream org {
       healthcheck_enabled;
       healthcheck_delay 5000;
       healthcheck_timeout 5000;
       healthcheck_failcount 1;
       server 10.194.1.107:8090  max_fails=2  fail_timeout=2s weight=2;
       server 10.194.1.108:8090  max_fails=2  fail_timeout=2s weight=2;
       server 10.194.100.50:8080 weight=5; ##Fallback
       sticky;
       ip_hash;
  }
   gzip on;
  server {
    listen 10.194.100.50:8080;
    server_tokens off;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
          return 444;
}
        index index.html;
        root /var/www;
        rewrite ^ http://10.194.100.50:8080/index.html;
}
   server {
    listen 10.194.100.50:80;
    server_name www.example.de;
    rewrite ^ http://www.example.de/de/examples/example.php?thisID=44
permanent;
}
  server {
    ssl on;
    ssl_prefer_server_ciphers on;
    ssl_protocols  SSLv3 TLSv1;
    ssl_ciphers  HIGH:!SSLv2:!ADH:!aNULL:!eNULL:!NULL;
    listen 10.194.100.50:443 ssl;
    ssl_certificate ssl/nginx-test.crt;
    ssl_certificate_key ssl/nginx-test.key;
    keepalive_timeout 60;
    server_tokens off;
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
          return 444;
}
    server_name org;
    location /org {
      proxy_pass http://org;
    }
    server_name online;
    location /online {
      proxy_pass http://online;
    }
  }
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,220113,220113#msg-220113



More information about the nginx mailing list