How to whitelist IPs in NGINX configuration?
Add this code in your .conf file if ($remote_addr = "14.51.20.3") { set $block_me_now "B"; } if ($remote_addr = "104.1.20.29") { set $block_me_now "B"; } if ($block_me_now != "B") { return 403; break; }
Add this code in your .conf file if ($remote_addr = "14.51.20.3") { set $block_me_now "B"; } if ($remote_addr = "104.1.20.29") { set $block_me_now "B"; } if ($block_me_now != "B") { return 403; break; }
The process involves matching all requests for an IP, if the IP does not match redirect all secured directory requests. RewriteCond %{REMOTE_ADDR} !^120\.120\.120\.120 RewriteRule ^admin/.* - [L,R=403] RewriteCond %{REMOTE_ADDR} ^120\.120\.120\.120 RewriteRule ^admin$ - [L,R=403] If you want to control this IP using a script, you can add 2 lines ###CUSTOM RULES### # your rules will appear here using php script ###CUSTOM RULES### Now add a script, say happy.php and use the following code: ...