nginx 拦截非法字符,nginx禁止url访问特定字符,nginx过滤url
off999 2025-01-20 15:40 24 浏览 0 评论
## nginx 拦截非法字符,nginx禁止url访问特定字符,nginx过滤url访问
参考代码一
#前缀为无限,后面的精准屏蔽字符 123
if ($request_uri ~* "123") {
return 403 "I've recorded your ip Wait to check the water meter";
}
参考代码二
#前缀为index.php,后面的精准屏蔽字符 123
if ($request_uri ~* "/index.php\123") {
return 403 "I've recorded your ip Wait to check the water meter";
}
参考代码三
location / {
# 当访问的url中含有/%#时返回404
if ($request_uri ~* "/%#") {
return 404;
}
#当访问url的后面带有?的链接 返回404
if ($request_uri ~* ^/a/m/(.*)\.html\?(.*)$) {
return 404;
}
}注释:
过滤链接中的?在nginx的配置文件中写入
location / {# 当访问的url中含有/%#时返回404if ($request_uri ~* "/%#") {return 404;}#
当访问url的后面带有?的链接 返回404if ($request_uri ~*^/a/m/(.*)\.html\?(.*)$) {return 404;
nginx 正则表达式
=开头表示精确匹配,如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。
^~ 开头表示uri以某个常规字符串开头,不是正则匹配
~ 开头表示区分大小写的正则匹配;
~* 开头表示不区分大小写的正则匹配
.* .匹配任意字符,*匹配数量0到正无穷;
\. \转义,匹配.
/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到
本站测试代码,小白一键复制(注:需要自行根据网站程序定义)
宝塔为例:/www/server/panel/vhost/nginx/你的网站域名.conf,复制代码点击保存
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "../../../../../../") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* ";") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "&") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "base64") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\&") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\?") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\;") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\=") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\=") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\_") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\./") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\:") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\base64") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\%") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\wp-content") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\;amp") {
return 403 "I've recorded your ip Wait to check the water meter";
}## 附带:nginx ql语句过滤、文件注入禁止、溢出攻击过滤、spam字段过滤、user-agents头过滤
sql语句过滤
if ($request_uri ~* "(cost\()|(concat\()") {
return 444;
}
if ($request_uri ~* "[+|(%20)]union[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]and[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]select[+|(%20)]") {
return 444;
}文件注入禁止
set $block_file_injections 0;
if ($query_string ~ “[a-zA-Z0-9_]=http://”) {
set $block_file_injections 1;
}
if ($query_string ~ “[a-zA-Z0-9_]=(\.\.//?)+”) {
set $block_file_injections 1;
}
if ($query_string ~ “[a-zA-Z0-9_]=/([a-z0-9_.]//?)+”) {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 444;
}溢出攻击过滤
set $block_common_exploits 0;
if ($query_string ~ “(<|%3C).*script.*(>|%3E)”) {
set $block_common_exploits 1;
}
if ($query_string ~ “GLOBALS(=|\[|\%[0-9A-Z]{0,2})”) {
set $block_common_exploits 1;
}
if ($query_string ~ “_REQUEST(=|\[|\%[0-9A-Z]{0,2})”) {
set $block_common_exploits 1;
}
if ($query_string ~ “proc/self/environ”) {
set $block_common_exploits 1;
}
if ($query_string ~ “mosConfig_[a-zA-Z_]{1,21}(=|\%3D)”) {
set $block_common_exploits 1;
}
if ($query_string ~ “base64_(en|de)code\(.*\)”) {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 444;
}spam字段过滤
set $block_spam 0;
if ($query_string ~ “\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b”) {
set $block_spam 1;
}
if ($block_spam = 1) {
return 444;
}user-agents头过滤
set $block_user_agents 0;
if ($http_user_agent ~ “Wget”) {
set $block_user_agents 1;
}
# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ “Indy Library”) {
set $block_user_agents 1;
}
# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ “libwww-perl”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GetRight”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GetWeb!”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Go!Zilla”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Download Demon”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Go-Ahead-Got-It”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “TurnitinBot”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GrabNet”) {
set $block_user_agents 1;
}
if ($block_user_agents = 1) {
return 444;
}
}自动防护
if ($request_uri ~* \.(htm|do)\?(.*)$) {
set $req $2;
}
if ($req ~* "(cost\()|(concat\()") {
return 503;
}
if ($req ~* "union[+|(%20)]") {
return 503;
}
if ($req ~* "and[+|(%20)]") {
return 503;
}
if ($req ~* "select[+|(%20)]") {
return 503;
}注:使用上也需要进行相应的调整
- 上一篇:Nginx限流配置详解
- 下一篇:Nginx的location指令
相关推荐
- 独一无二繁体字网名(独一无二繁体字网名大全)
-
超复杂网名用繁体字表示就应写成“超複雜”,看看复杂的繁体字“複雜”的写法是蛮复杂,所以简体字的运用大大方便了人们的使用。殺軟嬌貪歡張錯過樂極寵愛兩壹塹長壹牽帶?g??稀爱★?a流.浪.猪爱...
- 2025组装机配置清单(2020年组装机主流配置)
-
13代已经出了。现在入手12代英特尔平台性价比最高。这套在3000比较偏显卡,也可以显卡用影驰GTX16504GD6128Bit,价格1100,省下来的钱可以把内存升级为8G×2条16G。Cp...
- 宗门系统流小说排行榜(宗门系统文)
-
第一《史上第一祖师爷》作者:八月飞鹰短书评:系统主线任务:林锋开山立派,建立史上第一大宗门,林锋本人成为第一祖师。第二《修真门派掌门路》作者:齐可休书评:本命由天授,同参伴我行逍遥两相对,一道诵黄庭在...
- 水星路由器设置ip地址(水星路由器的ip地址怎么改)
-
mercury无线路由器设置IP地址的步骤如下: 1、先将宽带网线插到路由器的wan口,再插入电源插头。 2、在带有无线网卡的笔记本电脑上右击“网上邻居”,选择“属性”。 3、再右击“本地连接”...
- 正版w10系统多少钱
-
Windows10家庭版官方价格:888元Windows10专业版价格:1799元Windows10家庭版到专业版升级包价格:879元Windows10企业版价格:4200元Windows10教育版价...
- 七彩虹(七彩虹显卡)
-
https://www.colorful.cn/七彩虹于2005年深圳成立。深耕于电脑主机板卡硬件的二十年间,七彩虹完成了三大阶段的战略转型,成功地由计算机零组件代理商蜕变成为拥有自主研发、自主生产、...
- 华硕驱动下载专区(华硕官方驱动)
-
从华硕官网下载原装系统可以按以下步骤进行:1.打开华硕官网:https://www.asus.com/cn/。2.将鼠标移动到“支持”菜单上,并点击“驱动与工具”。3.在页面中找到“操作系统”选...
- 黑客教你破解wifi密码(黑客教你破解wifi密码是多少)
-
黑客是利用wifi的拼码,或者路由器的加密不强破解的,高级的黑客,在很短的时间内就可以破解密码繁杂的wifi你是用了别人的软件吧太相信别人了什么黑客。带一堆模块的玩意儿也叫黑客?黑客和骇客是两...
- 高仿ios主题全套软件(超高仿ios安卓主题)
-
IPhone12启动器全套仿Ios12桌面主题是一款能够让大家的安卓手机秒变苹果机的系统工具,IPhone12启动器可让你的手机直接变成IPhone12的桌面。从主题,桌面,Ui以及系统内的各种细节,...
- win10在哪里下载软件最好(win10软件在哪下载比较好)
-
1、点击Win10系统的开始菜单,然后在点击应用商店;2、打开Win10应用商店后,在搜索框里输入想要搜索的应用软件,然后点击检索;3、点击搜索到的应用,点击安装;4、点击安装后,系统会提示要切换到这...
- 电脑软件怎么安装(电脑软件怎么安装到手机上)
-
电脑怎么安装excel软件方法/步骤:1.在电脑左下角找到这个小圆圈,单击小圆圈打开搜索栏。搜索MicrosoftStore。2.在右上角找到搜索,单击搜索。在搜索中输入Excel。回车键打开。3....
- u盘win7系统安装盘(u盘里安装win7系统)
-
有些软件我们从网上下载安装时需要破解密码或者我们没有网时,直接需要把安装的软件,传到别的电脑,具体操作如下:1。直接把另一台电脑桌面上的软件复制或发送的优盘里,其实那只是一个快捷方式2.以ps软件为例...
- 语音输入法哪个好用(语音输入法免费版下载安装)
-
日常基本使用的讯飞和搜狗都还不错,对比来看的话,讯飞相对会更好一些。讯飞输入法在键盘输入方面进步非常快,功能也比较全面。单纯的语音方面,讯飞的稍微好一点,例如一些标点、断句之类处理的更加到位。讯飞支持...
- 手机app应用市场(手机里面的应用市场)
-
360手机助手是android智能手机的手机管理专家。提供海量的游戏、软件、音乐、小说、视频、图片,通过它轻松下载、安装、管理手机资源。所有提供信息资源,全部经过360安全检测中心的审核认证,绿色无毒...
-
- 开局最强系统(开局最强系统txt奇书网)
-
《最强奶爸系统》作者:最美猪猪小说简介同学甲:“我找到了月入七千的工作。”同学乙:“我找到了月入一万的工作。叶辰,你呢?”叶辰:“我老婆…是万亿市值超凡集团的老板,给我生了10个孩子。”同学们:???叶辰遭前女友陷害,阴差阳错邂逅了一位美女...
-
2026-01-03 07:03 off999
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
python入门到脱坑 输入与输出—str()函数
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
失业程序员复习python笔记——条件与循环
-
系统u盘安装(win11系统u盘安装)
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
