nginx bans an IP from accessing the site

WBOY
Release: 2016-08-08 09:27:27
Original
832 people have browsed it

There is an IP that is spamming the website, and I want to block this IP to prevent him from opening the website. After checking the information, many people on the Internet said that /etc/hosts.deny can be implemented. In fact, this is not possible. I don’t want to use iptable, it seems too troublesome. Directly check how nginx blocks IP access.

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

deny 4.4.4.4 //This is the IP that nginx wants to ban

Save it.

Add: include blocksip.conf to the nginx configuration file nginx.conf; and then restart nginx, and it will take effect. When a blocked IP opens a site, it will prompt:

403 Forbidden


blocksip.conf: There are many 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 network segment is written like this: 192.168.1.0/24.

The above introduces how nginx prohibits a certain IP from accessing the site, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!