PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] How to bypass nginx proxy a list of IPS

 September 01, 2022     nginx, nginx-config, nginx-reverse-proxy, whitelist     No comments   

Issue

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?


Solution

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.



Answered By - miknik
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing