Welcome! Log In Create A New Profile

Advanced

using try_files to choose proxy upstream

Posted by adriannye 
using try_files to choose proxy upstream
September 10, 2012 11:12AM
I have two identical web servers behind an nginx reverse proxy. Both web servers normally share the load but during redeployment I need to take one out of rotation. I want to control this using the presence or absence of files.
This way works but it is not symmetrical (file for node1 but not node2) and it requires these repeated location sections and repeated definitions of upstreams. Is there a cleaner way?

upstream web-both {
server web1-stage:8080 ;
server web2-stage:8080 ;

}

location / {
try_files /both.html @node1 ;
proxy_pass http://web-both;
}

location @node1 {
try_files /node.html @node2 ;
proxy_pass http://web1-stage:8080;
}

location @node2 {
proxy_pass http://web2-stage:8080;
}
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 179
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready