Welcome! Log In Create A New Profile

Advanced

Upstream for single IP

Posted by piotr.pawlowski 
Upstream for single IP
April 23, 2012 06:04AM
Dear all,

I am planning to configure laod balancing on NginX by using upstream module.
I will have two backend server and one front-end (which will accept all requests and pass them to backend servers).
Despite posibility to handle more requests to website, I would like to also use one of the backend servers for some testing purposes.
Now I am wondering if there is possibility to configure NginX with upstream module to redirect requests from single IP to backend-server1 while all other requests are going to be forwarded to backend-server2 .
Thank you in advance for any tips.

Regards
Piotr
Re: Upstream for single IP
April 24, 2012 06:17AM
OK, I've figured out how to do it.
I assume, that my upstream pool is called 'webservers' which consist two servers with IP 192.168.1.2 and 192.168.1.3. Now in configuration file for specific website you can use following configuration:

location / {
proxy_pass_header $server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
if ( $remote_addr = "MyIP" ) {
proxy_pass http://192.168.1.2:80;
}
if ( $remote_addr != "MyIP" ) {
proxy_pass http://192.168.1.3:80;
}
}

Where 'MyIP' is an IP address of the PC, from which would you like to perform testing.
Hope, that this will be useful for others.
Re: Upstream for single IP
April 25, 2012 06:38AM
Thanks for kicking this back , I wanted to do this for testing purposes as well!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 110
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready