# Upstream Fallback if Backends can´t be reached

**URL:** <https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913>\
**Category:** NGINX\
**Created:** [December 15, 2011, 5:11pm UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913 "2011-12-15T17:11:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 15, 2011, 5:11pm UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913/1 "2011-12-15T17:11:24Z")

</div>

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](http://10.194.100.50:8080/index.html);  
}  
server {  
listen 10.194.100.50:80;  
server\_name [www.example.de](http://www.example.de);  
rewrite ^ [http://www.example.de/de/examples/example.php?thisID=44](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](http://org);  
}  
server\_name online;  
location /online {  
proxy\_pass [http://online](http://online);  
}  
}  
}

Posted at Nginx Forum:

> **[Upstream Fallback if Backends can´t be reached](https://forum.nginx.org/read.php?2,220113,220113#msg-220113)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![kperas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/0ea827/32.png) [@kperas](https://www.ruby-forum.com/u/kperas)\
**Post date:** [December 16, 2011, 1:29am UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913/2 "2011-12-16T01:29:53Z")

</div>

> location /org {  
> proxy\_pass [http://org](http://org);  
> }

Something like:

proxy\_intercept\_errors on;

location /org {  
proxy\_pass [http://org](http://org);  
error\_page 502 503 504 /error/page.html  
}

location /error {  
root /path/to/my/error/pages;  
}

Maybe?  
Probably have typos, done from memory

---

<div class="post-metadata">

**Author:** ![kperas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/0ea827/32.png) [@kperas](https://www.ruby-forum.com/u/kperas)\
**Post date:** [December 16, 2011, 8:20am UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913/3 "2011-12-16T08:20:15Z")

</div>

Hi Brian,

thanks a lot. I will try that today.

Greets

Posted at Nginx Forum:

> **[Re: Upstream Fallback if Backends can´t be reached](https://forum.nginx.org/read.php?2,220113,220147#msg-220147)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![kperas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/0ea827/32.png) [@kperas](https://www.ruby-forum.com/u/kperas)\
**Post date:** [December 16, 2011, 2:02pm UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913/4 "2011-12-16T14:02:49Z")

</div>

Hi Brian, that works like a charm! Thanks a lot!

But now i have some other but close requirement.

Right now i´m browsing to my site with URL  
[https://10.194.100.50/example-online](https://10.194.100.50/example-online) or [https://10.194.100.50/examle-org](https://10.194.100.50/examle-org)  
and everything works. But if i go to [https://10.194.100.50](https://10.194.100.50) i get  
“Welcome to nginx” and if i go to [https://10.194.100.50/exaaaapleeeee](https://10.194.100.50/exaaaapleeeee)  
(wrong target) i get “404 Not found” “nginx”

I would like to have all wrong URLs within [https://10.194.100.50](https://10.194.100.50) to go  
to my error.html

Is that possible?

Thanks in advance

Posted at Nginx Forum:

> **[Re: Upstream Fallback if Backends can´t be reached](https://forum.nginx.org/read.php?2,220113,220161#msg-220161)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![kperas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/0ea827/32.png) [@kperas](https://www.ruby-forum.com/u/kperas)\
**Post date:** [December 16, 2011, 2:04pm UTC](https://www.ruby-forum.com/t/upstream-fallback-if-backends-can-t-be-reached/214913/5 "2011-12-16T14:04:03Z")

</div>

here is my current nginx.conf:

##########################################  
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 example-online {  
healthcheck\_enabled;  
healthcheck\_delay 5000;  
healthcheck\_timeout 5000;  
healthcheck\_failcount 1;  
server 10.194.1.107:8080 max\_fails=2 fail\_timeout=2s weight=2;  
## server 10.194.1.108:8080 max\_fails=2 fail\_timeout=2s weight=2;  
sticky;  
ip\_hash;  
}  
upstream example-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;  
sticky;  
ip\_hash;  
}  
gzip on;  
server {  
listen 10.194.100.50:80;  
server\_name [example.de](http://example.de) [www.example.de](http://www.example.de);  
rewrite ^ [http://www.testing.de](http://www.testing.de) 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;  
proxy\_intercept\_errors on;  
if ($request\_method !~ ^(GET|HEAD|POST)$ ) {  
return 444;  
}  
if ($http\_user\_agent ~\* LWP::Simple|BBBike|wget) {  
return 403;  
}  
if ( $http\_referer ~\*  
(babes|forsale|girl|jewelry|love|nudit|organic|poker|porn|sex|teen) ) {  
return 403;  
}  
server\_name example-org;  
location /example-org {  
proxy\_pass [http://example-org](http://example-org);  
error\_page 400 401 404 408 502 503 504 /error/error.html;  
}  
server\_name example-online;  
location /example-online {  
proxy\_pass [http://example-online](http://example-online);  
error\_page 400 401 404 408 502 503 504 /error/error.html;  
}  
location /error {  
root /var/www;  
}  
location / {  
root /var/www/error;  
index error.html;  
}  
}  
}  
###########################

Posted at Nginx Forum:

> **[Re: Upstream Fallback if Backends can´t be reached](https://forum.nginx.org/read.php?2,220113,220162#msg-220162)**
>
> 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...
