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

Nginx的安全规则配置

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


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的安全规则配置” 的相关文章

网站实现动静分离教程

网站实现动静分离的参考教程:张戈博客教程地址参考:https://zhang.ge/5130.html大鸟博客教程地址参考:https://www.daniao.org/2590.html张戈博客的nginx设置参考:server     { &n...

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

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

免费版cloudflare如何防CC攻击?不需要动手写规则!

以下操作不需要您会写规则,不需要您分析流量,小白式的操作,随便点点鼠标就行了。非常简单!哪怕超过千万/亿次攻击,1H1G也防得住,网站不会挂,收录不会掉,API也不会影响!确定您的网站被CF保护,也就是说DNS→是打开了代理,A/AAAA解析是橙色。(如果您之前IP漏了,那么就需要换IP)保护之前请...

Linux reinstall:服务器系统一键重装脚本

转自loc:https://hostloc.com/thread-1094336-1-3.html项目地址,欢迎 star:https://github.com/leitbogioro/Tools萌咖的一键重装脚本近期经过更新,已经支持 Debian 11/Ubuntu 20.04 等新系统,加入了...

redis清空缓存内容

有时候Wordpress开启redis缓存后会导致后天进不去跳转到首页的问题,排查下来原因可能是redis导致的,我们来手动清除一下redis对缓存教程开始ssh连接后 输入 redis-cli 进入redis,执行 flushall 出现OK这清除完成,然后输入 exit 退出即可。[root@V...

vim操作命令

在命令状态下对当前行用== (连按=两次), 或对多行用n==(n是自然数)表示自动缩进从当前行起的下面n行。你可以试试把代码缩进任意打乱再用n==排版,相当于一般IDE里的code format。使用gg=G可对整篇代码进行排版。 vim 选择文本,删除,复制,粘贴  文本的选...

发表评论

访客

看不清,换一张

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