skip to Main Content

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?

2

Answers


  1. 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

    Login or Signup to reply.
  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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search