Subrequest failover

I am trying to use nginx as reverse proxy to perform failover from 1
critical service to another.

When processing a request, it sends a request (http GET) to a backend
(custom http server) using SubRequest methods. If it is for some
reason down, and there is no response, i’d like it to fail over to a
second server. Is there a way to do this in conf settings or do I
have to make code modifications to accomplish this?

Any help appreciated.

-James-

29.07.2010, 04:36, “James Lyons” [email protected]:

I am trying to use nginx as reverse proxy to perform failover from 1
critical service to another.

When processing a request, it sends a request (http GET) to a backend
(custom http server) using SubRequest methods. If it is for some
reason down, and there is no response, i’d like it to fail over to a
second server. Is there a way to do this in conf settings or do I
have to make code modifications to accomplish this?

Any help appreciated.

upstream failover {
server 1.1.1.1;
server 2.2.2.2 backup;
}

server {
[…]
location / {
proxy_pass http://failover;
}
[…]
}

br, Denis F. Latypoff.

Hello!

On Wed, Jul 28, 2010 at 05:36:11PM -0700, James Lyons wrote:

I am trying to use nginx as reverse proxy to perform failover from 1
critical service to another.

When processing a request, it sends a request (http GET) to a backend
(custom http server) using SubRequest methods. If it is for some
reason down, and there is no response, i’d like it to fail over to a
second server. Is there a way to do this in conf settings or do I
have to make code modifications to accomplish this?

Subrequests in nginx aren’t really different from ordinary
requests, they are handled in the same way - with location
matching and so on. Setting failover correctly in config (either
with proxy_next_upstream or via error_page) would do the trick for
both normal requests and subrequests.

Maxim D.

so lets say I have a config that looks like:
upstream somename {
server www.somename1.net:80;
server www.somename2.net:80;
server www.somename3.net:80;
}

location /data/ {

proxy_pass http://somename/data/;
}

These names are processed as round robin I assume, but if a connection
to one fails – it won’t retry elsewhere.
To get that, i need to specify backup like in the example below. But
can I similarly specify multiple backups and have those load balanced
as well?

upstream somename {
server www.somename1.net:80;
server www.somename2.net:80;
server www.somename3.net:80;
server www.backupname1.net:80 backup;
server www.backupname2.net:80 backup;
server www.backupname3.net:80 backup;
}

location /data/ {

proxy_pass http://somename/data/;

}

Thanks so much for help so far – with what nginx version is “backup”
introduced?
I have:
378 upstream iks {
379 server 127.0.0.1:5397;
380 server www.testfailover.net:5397 backup;
381 }

on startup I see:
2010/09/14 18:46:46 [emerg] 17835#0: invalid parameter “backup” in
/box/etc/nginx/nginx.conf.iksdev:380

I know we are using 0.6.39 – which is old, so i suspect this is the
problem – but my job has been reluctant to upgrade so far. Is there
a workaround?

Hello!

On Tue, Sep 14, 2010 at 06:02:20PM -0700, James Lyons wrote:

}

These names are processed as round robin I assume, but if a connection
to one fails – it won’t retry elsewhere.

It will.

http://wiki.nginx.org/NginxHttpProxyModule#proxy_next_upstream

To get that, i need to specify backup like in the example below.

Backup servers are only tried if all normal servers were detected
to be down.

But can I similarly specify multiple backups and have those load balanced
as well?

Yes.

Maxim D.

Hello!

On Tue, Sep 14, 2010 at 06:56:38PM -0700, James Lyons wrote:

Thanks so much for help so far – with what nginx version is “backup”
introduced?

0.6.7+

See here:
http://nginx.org/en/CHANGES

I know we are using 0.6.39 – which is old, so i suspect this is the
problem – but my job has been reluctant to upgrade so far. Is there
a workaround?

Please make sure you define upstream before you try to use it in
any proxy_pass.

Maxim D.

p.s. Please do not top-post. Thank you.

I’m also having strange issue with backup statement. Here’s my config

upstream test {
  server 10.0.0.1;
  server 10.0.0.2 backup;
}

upstream proxy {
  server 94.1.1.1;
#  server 95.1.1.1 backup;
}

server {
  listen 80;
  server_name _;

  access_log off;

  location / {
    proxy_pass http://proxy;
#    proxy_pass http://test;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    client_max_body_size       100m;
    client_body_buffer_size    128k;
  }
}

It shows no errors on nginx -t run but as I uncomment “server 95.1.1.1
backup;” line it outputs

[emerg]: invalid parameter "backup" in /etc/nginx/sites-enabled/site:8
configuration file /etc/nginx/nginx.conf test failed

No errors in “upstream test” section. Why is that? Tried nginx 0.7.67-3
and 0.6.32-3 from debian packages.

Posted at Nginx Forum:

Hello!

On Thu, Sep 16, 2010 at 05:29:21AM -0400, reaper wrote:

}
proxy_set_header Host $host;

[emerg]: invalid parameter "backup" in /etc/nginx/sites-enabled/site:8
> configuration file /etc/nginx/nginx.conf test failed

No errors in “upstream test” section. Why is that? Tried nginx 0.7.67-3
and 0.6.32-3 from debian packages.

Most likely you have upstream “proxy” already defined somewhere
before your “upstream proxy” block, e.g. implicitly via

proxy_pass http://proxy;

or something like this.

Maxim D.