Nginx Deny From IP

Nginx is a very unique Web Server, today I will show how to deny IP using Nginx, Please note you must have this module installed in your Nginx web server , If you don’t have it installed – Simply download my pre-compile Nginx which comes with all the necessary modules known to NGINX.

ngx_http_access_module

Will create a file under our conf directory lets called that block.conf, My conf directory is located at /etc/nginx/conf.d/.

We are going to assume YOUR IP Address i.e. 8.8.8.8 & 8.8.4.4

nano /etc/nginx/conf.d/block.conf

deny 9.9.9.9;
deny 8.8.8.8;
deny 8.8.4.4;

Once done restart your Nginx server

service nginx restart OR
service nginx reload

Great source to obtain fresh IP addresses is from Ip2location

You pick and choose any country from the above link and wont allow them access to your server.

Leave a Reply

Your email address will not be published. Required fields are marked *