Nginx disables an IP address from accessing the site

Source: Internet
Author: User
: This article describes how to disable an IP address from accessing the site through nginx. For more information about PHP tutorials, see. If you want to block an IP address from your website, you cannot open the website. For more information, see/etc/hosts. deny. Actually, it is not feasible. I don't want to use iptable. it's too troublesome. Check nginx to prevent ip access.

First, create the following configuration file and place it under the nginx conf directory, and name it blocksip. conf:

Deny 4.4.4.4 // This is the IP address to be disabled by nginx

Save it.

Add: include blocksip. conf to the nginx configuration file nginx. conf, and restart nginx to take effect. When the blocked ip address opens the site, the following message is displayed:

403 Forbidden


Blocksip. conf: There are many other formats. you can configure only allowed IP access or IP segment access:
Deny IP;
Allow IP;
# Block all ips
Deny all;
# Allow all ips
Allow all;
The CIDR block format is as follows: 192.168.1.0/24.

The above section describes how to disable an IP address from accessing the site in nginx, including some content. if you are interested in the PHP Tutorial.

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.