0

I want to use a test server for administrators.

Is there a way to assign an access from the client of ip(123.0.0.1) to the server of ip(123.0.0.2)?

upstream target-server {  
  server [123.0.0.3] ;
  server [123.0.0.2] ;
}
alexander.polomodov
  • 1,060
  • 3
  • 10
  • 14
Fehoon
  • 33
  • 4

1 Answers1

0

You may use if statement in location to map traffic to your service.

upstream target-server {
server 123.0.0.3 ; 
server 123.0.0.2 ; }
server{
***
  location / {
    if ($remote_addr = 123.0.0.1) {
          proxy_pass http://123.0.0.2 ;
    }
    proxy_pass http://target-server ;
  }
}
user2986553
  • 390
  • 1
  • 4
  • I want to use like this . 123.0.0.*(all) how can i do ?? – Fehoon Jul 31 '18 at 09:42
  • I believe something like ($remote_addr ~ 123.0.0 ) within if condition may work. There are multiple conditions in nginx. For example this https://gist.github.com/jrom/1760790 – user2986553 Jul 31 '18 at 13:27