Skip to content

Nginx 屏蔽 IP

blacklist.conf

nginx
deny 127.0.0.1;
# 屏蔽单 IP
deny 127.0.0.1 192.168.1.1;
# 屏蔽多 IP
deny 127.0.0.0/8;
# 屏蔽网段 127.0.0.1 ~ 127.255.255.254
deny 127.255.0.0/16
# 屏蔽网段 127.255.0.1 ~ 127.255.255.254
deny 127.255.255.0/24
# 屏蔽网段 127.255.255.1 ~ 127.255.255.254

配置

LNMP

全局屏蔽

/usr/local/nginx/conf中创建blacklist.conf
各网站conf分别添加:

nginx
include blacklist.conf;

独立屏蔽

/usr/local/nginx/conf中创建blacklist目录并在目录中创建各站点domain.com.conf
各网站conf分别添加:

nginx
include blacklist/domain.com.conf;

DNMP

全局屏蔽

/path/dnmp/services/nginx/conf.d中创建blacklist.conf
各网站conf分别添加:

nginx
include conf.d/blacklist.conf;

独立屏蔽

/path/dnmp/services/nginx/conf.d中创建blacklist目录并在目录中创建各站点domain.com.conf

nginx
include conf.d/blacklist/domain.com.conf;