nginx 过滤某个url请求

发布时间:2023年10月02日 阅读:66 次

最近上线一个业务,结果这个接口的业务逻辑查库末加索引,数据库直接boom,只能临时处理,将这个接口的请求过滤,不经过后端逻辑直接返回。nginx 配置修改如下:

 

server{listen 80;server_name xx.xx.com;index index.html index.htm index.php;root  /data/xxx;charset utf-8;location ~.*\.(css|js|swf|jpg|gif|png|jpep|jpg|mp3|xx|xmlbak|xml)$ {expires       720h;}location ~ .*\.php${include fcgi.conf;fastcgi_pass  127.0.0.1:xxx;fastcgi_index index.php;expires off;}##过滤段location ~ / {if ( $query_string ~* ^(.*)?s=test/xxx/getAAInfo ){return 555;}}access_log  /data/logs/xxx.log  access;}

nginx 正则表达式

=开头表示精确匹配,如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。

^~ 开头表示uri以某个常规字符串开头,不是正则匹配

~ 开头表示区分大小写的正则匹配;

~* 开头表示不区分大小写的正则匹配

.*   .匹配任意字符,*匹配数量0到正无穷;

\.   \转义,匹配. 

/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到

 

最近上线一个业务,结果这个接口的业务逻辑查库末加索引,数据库直接boom,只能临时处理,将这个接口的请求过滤,不经过后端逻辑直接返回。nginx 配置修改如下:

 

server{listen 80;server_name xx.xx.com;index index.html index.htm index.php;root  /data/xxx;charset utf-8;location ~.*\.(css|js|swf|jpg|gif|png|jpep|jpg|mp3|xx|xmlbak|xml)$ {expires       720h;}location ~ .*\.php${include fcgi.conf;fastcgi_pass  127.0.0.1:xxx;fastcgi_index index.php;expires off;}##过滤段location ~ / {if ( $query_string ~* ^(.*)?s=test/xxx/getAAInfo ){return 555;}}access_log  /data/logs/xxx.log  access;}

nginx 正则表达式

=开头表示精确匹配,如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。

^~ 开头表示uri以某个常规字符串开头,不是正则匹配

~ 开头表示区分大小写的正则匹配;

~* 开头表示不区分大小写的正则匹配

.*   .匹配任意字符,*匹配数量0到正无穷;

\.   \转义,匹配. 

/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到

 


Tag:
相关文章

发表评论:取消回复