当前位置:首页 > 教程收藏 > 正文内容

Nginx的安全规则配置

fanren4年前 (2022-07-10)教程收藏123


if ($request_uri ~* "(\.gz)|(\")|(\.tar)|(admin)|(\.zip)|(\.sql)|(\.asp)|(\.rar)|(function)|($_GET)|(eval)|(\?php)|(config)|(\')|(\.bak)") {
return 301 http://lg-dene.fdcservers.net/10GBtest.zip;
}
#禁止下载以 XXX 后缀的文件
location ~ \.(zip|rar|sql|bak|gz|7z)$
{
    return 444;
}
#访问链接里含有 test 直接跳转到公安网
if ($request_uri ~* test=) {
return 301 https://www.mps.gov.cn;
}
if ($http_user_agent ~* (SemrushBot|python|MJ12bot|AhrefsBot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup)) {
      return 444;
    }


后续补充:

 #请求这些敏感词时跳转下载10g文件
 if ($request_uri ~* "(\.gz)|(\")|(\.tar)|(admin)|(\.zip)|(\.sql)|(\.asp)|(\.rar)|(function)|($_GET)|(eval)|(\?php)|(config)|(\')|(\.bak)") {
            return 301 http://lg-dene.fdcservers.net/10GBtest.zip;
        }
 #禁止下载以 XXX 后缀的文件
 location ~ \.(zip|rar|sql|bak|gz|7z)$ 
 { 
   return 444;
  }
 #访问链接里含有 test 直接跳转到公安网
 if ($request_uri ~* test=) {
  return 301 https://www.mps.gov.cn;
 }
 #防止SB爬虫
 if ($http_user_agent ~* (SemrushBot|python|MJ12bot|AhrefsBot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup)) {
      return 444;
    }
 #屏蔽非常见蜘蛛爬虫配置
 if ($http_user_agent ~* (SemrushBot|python|MJ12bot|AhrefsBot|AhrefsBot|hubspot|opensiteexplorer|leiki|webmeup)) {
     return 444;
  }
 #禁止某个目录执行脚本
#uploads|templets|data 这些目录禁止执行PHP
 location ~* ^/(uploads|templets|data)/.*.(php|php5)$ {
    return 444;
  }



参考地址:https://hostloc.com/thread-1044768-1-2.html

“Nginx的安全规则配置” 的相关文章

甲骨文小鸡开机后的常用脚本

Root权限:sudo -iRoot密码修改:bash <(curl -Ls https://github.com/baoqihui/script/raw/main/root.sh)或sudo -iwget -N https://cdn.jsdelivr.net/gh/Misaka-blog/...

LinuxMirrors — 一键脚本彻底解决linux换源问题

国内vps安装好linux系统后(centos,debian,ubuntu等),除了deepin以外,其他Linux发行版从官方源下载东西都很慢,这个时候,我们就需要给自己的系统换一个镜像源了,使用镜像源不仅可以给官方源的服务器减压,还能提供更快的速度。这也是为啥,我们总需要换源的原因!!当然,换源...

宝塔面板离线降级版本步骤

宝塔面板离线降级版本步骤cd /root && wget http://download.bt.cn/install/update/LinuxPanel-7.4.5.zip unzip LinuxPanel-7.4.5.zip c...

【2023脚本收集】常用脚本备份

转自loc:https://hostloc.com/thread-1097221-1-2.html DD网络重装脚本PS:自定义密码直接 -p 你想要的密码就行!!!部分机器需要设置网卡,否则可以VNC,但是不能远程SSH-firmware        &n...

zblog批量修改文章发布状态

本案例为通过txt文档输入N多个文章id,然后根据txt输入的ID批量对文章状态进行修改。操作步骤如下:1、在网站根目录创建txt文件,命名为id.txt;2、在txt里面批量写入需要修改状态的id,每个id占一行;3、在网站根目录创建php文件,命名为id.php;4、在文件内写入php代码<...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。