0

I have an Nginx config with the redirect to holding pages:

    location / {
        ...
        if ($setholdingpage = 'True') {
        rewrite (^.*$) /holding-page last;
        }
           proxy_pass $backend;
    }

Also, I have a list of IPs that should be whitelisted and not redirected to holding pages. How it's possible to do?

apaderno
  • 28,547
  • 16
  • 75
  • 90
fireman777
  • 134
  • 1
  • 15

2 Answers2

2

You can use the Nginx geo module to create a variable based upon client IP address, you can specify individual IP addresses or CIDR ranges:

geo $bypassip {
  default 0;

  64.233.160.0/19 1;
  66.102.0.0/20 1;
}

Then override your variable if the IP matches one in your list:

if ($bypassip = 1){
  set $setholdingpage False;
}

I use a similar setup to block certain geographic regions but still allow Google crawlers to access my site.

miknik
  • 5,748
  • 1
  • 10
  • 26
0

You can make use of the allow deny directives.

If I get you correct the whitelist will be your $setholdingpage variable in some sort?

try this

server {

error_page 403=@holding;

location / {
  allow 127.0.0.1;
  allow 192.168.1.0/24;
  deny all;

  proxy_pass http://backend;

}

location /@holding {
  root /path/to/your/holding/html;
  index holdingv1.html;
}

}

This will send the non-whitelisted IPs to the error-page you specified. The error_page can be in the location as well.

Not tested but this should do the trick.

References: http://nginx.org/en/docs/http/ngx_http_access_module.html#allow

Timo Stark
  • 2,721
  • 1
  • 10
  • 23