I've got a case where I need to do a different proxy pass in Nginx depending on which CIDR the client's IP address is part of.
So, for example, let's say I have the following CIDRs:
10.50.0.0/16
10.51.0.0/16
10.52.0.0/16
Each of those client addresses needs to have a different proxy_pass in Nginx. How would I go about doing this? I'm very new to Nginx so achieving things like this are still a bit confusing.
You could use Geo module. Your configuration then would look somewhat like this:
geo $upstream {
default default_upstream;
10.50.0.0/16 some_upstream;
10.51.0.0/16 another_upstream;
}
upstream default_upstream {
server 192.168.0.1:80;
}
upstream some_upstream {
server 192.168.0.2:80;
}
upstream another_upstream {
server 192.168.0.3:80;
}
server {
...
location ... {
...
proxy_pass http://$upstream;
}
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With