Dec 13, 2014

0 Block & deny IP address with Nginx

How to deny access based on the  IP address with Nginx.

# Create block config file.
touch /etc/nginx/blockips.conf

#Edit nginx.conf file
nano /etc/nginx/nginx.conf

        #Add this line in http section

        ## IP block list  ##
        include blockips.conf;

# Add your unwanted IP's
nano /etc/nginx/blockips.conf

Example : 

deny 192.168.45.0;
deny 92.112.65.2;

# Add configuration for 403 error message

nano /etc/nginx/sites-available/default  [or name of your own]

# In " server { " section add : 

# redirect server error pages to the static page
         error_page   403  /error403.html;
         location = /error403.html {
         root /var/www;
         allow all;

# Create file "error403.html" in directory /var/www
nano /var/www/error403.html

# In error403.html you can add your text 
# Example : 

         <html>
         <head><title>Error 403 - Access denied!</title></head>
         <body>
         You do not have access to this page, and you probably know why.
         </body>
         </html>

# Change file permissions

sudo chown -R www-data:www-data /var/www/

# Restart nginx
service nginx restart



0 comments :

Post a Comment

Comment: