项目

通用

个人资料

操作

模块 mod_access

描述

访问模块用于拒绝文件访问。

选项

url.access-allow
仅允许访问具有给定尾随路径名的文件。(自 1.4.40 起)
默认值:空

url.access-deny
拒绝访问所有具有给定尾随路径名的文件。
默认值:空

使用示例

url.access-allow

    url.access-allow = ( ".jpg", ".gif")

您可能希望拒绝访问所有以波浪号(~)或 .inc 结尾的文件,因为:

  1. 文本编辑器通常使用尾随波浪号作为备份文件。
  2. 而 .inc 扩展名通常用于包含代码的文件。

url.access-deny

    url.access-deny = ( "~", ".inc")

目录拒绝访问
url.access-deny 中的空字符串匹配所有请求

    $HTTP["url"] =~ "^/libraries" {
        url.access-deny = ("")
    }

注意:创建非常非常长的条件列表效率低下。如果从列表中创建条件,请考虑将它们与正则表达式交替分批处理成更少的条件,每个条件都包含一个大型正则表达式。参见 #3074

如果 User-Agent 匹配 robots.txt,则拒绝机器人访问
生成配置的示例单行命令
curl -s https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/robots.txt/robots.txt | perl -e 'while (<>) { /User-agent:\s*(.+)/ && push @x, quotemeta($1); } print "\$HTTP[\"user-agent\"] =~ \"\\b(?i:", join("|",@x), ")\\b\" { url.access-deny = (\"\") }\n"'

大量拒绝
https://github.com/mitchellkrogza
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
以下将 globalblacklist.conf 中的一些拒绝规则转换为 lighttpd 语法。在 lighttpd.conf 中添加 include "/path/to/rejections" 之前,您应该查看输出文件 rejections。IP 地址可能更适合放在防火墙规则中。是的,这可以清理得更简洁,而不是一个巨大的 Perl 单行命令,但这是对 #3074 的快速回应,其他人可能会觉得有用,所以这是一个起点。

curl -s https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master/conf.d/globalblacklist.conf | perl -e '$/=undef; $list=<>; while ($list =~ /^# START ([^#]+) ### DO NOT EDIT THIS LINE AT ALL ###$(.*?)# END \1 ### DO NOT EDIT THIS LINE AT ALL ###/gms) { $x{$1} = $2; } /\(\?:\\b\)(.+?)\(\?:\\b\)/ && push @bad_bots, $1 foreach split("\n",$x{"BAD BOTS"}); /\(\?:\\b\)(.+?)\(\?:\\b\)/ && push @bad_referrers, $1 foreach split("\n",$x{"BAD REFERRERS"}); /\s*(\S+)\s*1;/ && push @bad_ips, $1 foreach split("\n",$x{"KNOWN BAD IP ADDRESSES"}); undef @strs; $str=""; foreach (@bad_bots) { $str .= $_."|"; if (length($str) > 32000) { substr($str,-1,1,""); push @strs, $str; $str=""; } } substr($str,-1,1,""); push @strs, $str; print "\$HTTP[\"user-agent\"] =~ \"\\b(?i:$_)\\b\" { url.access-deny = ( \"\" ) }\n\n" foreach (@strs); undef @strs; $str=""; foreach (@bad_referrers) { $str .= $_."|"; if (length($str) > 32000) { substr($str,-1,1,""); push @strs, $str; $str=""; } } substr($str,-1,1,""); push @strs, $str; print "\$HTTP[\"referer\"] =~ \"(?:\\.|^)(?i:$_)\$\" { url.access-deny = ( \"\" ) }\n\n" foreach (@strs); undef @strs; $str=""; foreach (@bad_ips) { $str .= quotemeta($_)."|"; if (length($str) > 32000) { substr($str,-1,1,""); push @strs, $str; $str=""; } } substr($str,-1,1,""); push @strs, $str; print "\$HTTP[\"remote-ip\"] =~ \"^(?:$_)\$\" { url.access-deny = ( \"\" ) }\n\n" foreach (@strs);' > rejections

gstrauss 3 个月前更新 · 29 次修订