Nginx/Apache server shielding IP address and IP Segment Configuration tutorial

Source: Internet
Author: User
Tags website ip
If we need to block an IP address or an IP segment in our VPS and server, we can directly add it to the Nginx and Apache rules. This usage is often useful, for example, it is not allowed to access a user's IP address or spider crawling information, or even some collection and image IP addresses need to be blocked. Although this function has not yet been used by Lao Jiang, it has been recorded by some netizens and can be directly used if necessary.

 

1. Apache environment

 

If the server is an Apache environment, add the following file directly to the. htaccess file in the current root directory.

 

The code is as follows: Copy code

Order allow, deny
Deny from 220.116.0.0 # shield an IP address
Deny from 220.116.0.0/14 # Blocked IP segments
Allow from all

 

Directly add it to the. htaccess file in our root directory. It takes effect immediately without restarting.

 

II. Nginx environment

 

Nginx is slightly different. You need to use a blocking IP list file (blockip. conf) and then add a blocking IP address and IP segment.

 

The code is as follows: Copy code

Deny 220.116.0.0; // block an IP address
Deny 220.116.0.0/14; // block the IP address segment

 

Then edit the nginx. conf configuration file.

 

The code is as follows: Copy code

Include blockip. conf;

 

This file can be added in http {}, server {}, but note the relative path. We can place blockip. conf in a directory with the Nginx. conf file. Of course, we can also shield a single website IP address from the conf file of the current website.

 

Restart Nginx to take effect.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.