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; }

June 8, 2020 · 1 min · Harshvardhan Malpani

How to secure a folder by whitelisting one IP using HTACCESS and denying all others

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

October 26, 2017 · 1 min · Harshvardhan Malpani