0

How to allow trusted IP only and deny all other IP in nginx

I' m new for nginx. i don' t know how to deny all unwanted ip' s in nginx, if any body knows solution please post here...!!!

Nginx IP Address Add a comment
dylan
asked Sep 19 2017

Answer

0

"create blockips.conf in /usr/local/nginx/conf/, enter

#vi blockips.conf
Append / add entries as follows:
deny 1.2.3.4;
deny 91.212.45.0/24;
deny 91.212.65.0/24;

Save and close the file. Test the config file, enter:

#/usr/local/nginx/sbin/nginx -t

Finally,
Reload the new config, enter

#/usr/local/nginx/sbin/nginx -s reload

If allow ....
location / {
  #block one workstation
  deny    192.168.1.1;
  #allow anyone in 192.168.1.0/24
  allow   192.168.1.0/24;
  #drop rest of the world 
  deny    all;"
Add a comment
linuxhelp
asked Jan 14 2019
edited Jan 14 2019
Post your Answer