文章目录
隐藏
不常用,仅作记录,防止记不住,省得每次查
IP/IP段
新建 blacklist.conf,按照以下格式写入内容
# IP deny xxx.xxx.xxx.xxx; # IP 段 deny xxx.xxx.xxx.xxx/xx;
然后在配置文件 nginx.conf 的 http 块中引入这个文件
http { # ... include /path/to/blacklist.conf; }
User Agent
在对应 server 块中按照以下格式加入欲屏蔽的 UA 关键字
# 大小写敏感 if ($http_user_agent ~ (KeyWord1|KeyWord2|...)) { return 403; # 或其他状态码 } # 大小写不敏感 if ($http_user_agent ~* (KeyWord1|KeyWord2|...)) { return 403; # 或其他状态码 }
之后重载 Nginx