T
T
tefoxis2020-04-22 15:06:38
Nginx
tefoxis, 2020-04-22 15:06:38

nginx. How to map internal subnets to fulfill the condition for them?

Hello everyone

I want to make it so that for users from the local network of the office a different proxy_pass is performed, unlike users from outside.

I'm trying to do so

map $remote_addr $internal {
default off;
192.168.100.0/24 on;
192.168.200.0.24 on; 
}

server {
..........
location /ops{
 if ($internal = on){
   proxy_pass ip_proxy1;
 }
 proxy_pass ip_proxy2;
}
.........
}

But it doesn't work( What am I doing wrong? Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-04-22
@q2digger

I did something like this.
in main config

geo $bad_user { 
  default 1;
  192.168.0.0/16 0;
}

In virthost
if ($bad_user) {
      proxy_pass http://blah-blah-blah;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question