我的 Apache 2.4 (CentOS 7) 服务器托管多个网站。有时,在访问任何网站文件(主要是 php 脚本)时,我会收到 403 Forbidden(您无权访问此服务器上的文件 X)错误。按 F5 几秒钟将解决它并正常加载页面。这些文件具有正确的权限。我也启用了 mod_evasive,但日志没有显示当时任何 IP 被阻止。
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
cloudflare_module (shared)
access_compat_module (shared)
actions_module (shared)
alias_module (shared)
allowmethods_module (shared)
auth_basic_module (shared)
auth_digest_module (shared)
authn_anon_module (shared)
authn_core_module (shared)
authn_dbd_module (shared)
authn_dbm_module (shared)
authn_file_module (shared)
authn_socache_module (shared)
authz_core_module (shared)
authz_dbd_module (shared)
authz_dbm_module (shared)
authz_groupfile_module (shared)
authz_host_module (shared)
authz_owner_module (shared)
authz_user_module (shared)
autoindex_module (shared)
cache_module (shared)
cache_disk_module (shared)
data_module (shared)
dbd_module (shared)
deflate_module (shared)
dir_module (shared)
dumpio_module (shared)
echo_module (shared)
env_module (shared)
expires_module (shared)
ext_filter_module (shared)
filter_module (shared)
headers_module (shared)
include_module (shared)
info_module (shared)
log_config_module (shared)
logio_module (shared)
mime_magic_module (shared)
mime_module (shared)
negotiation_module (shared)
remoteip_module (shared)
reqtimeout_module (shared)
rewrite_module (shared)
setenvif_module (shared)
slotmem_plain_module (shared)
slotmem_shm_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
socache_shmcb_module (shared)
status_module (shared)
substitute_module (shared)
suexec_module (shared)
unique_id_module (shared)
unixd_module (shared)
userdir_module (shared)
version_module (shared)
vhost_alias_module (shared)
dav_module (shared)
dav_fs_module (shared)
dav_lock_module (shared)
lua_module (shared)
mpm_prefork_module (shared)
proxy_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_heartbeat_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_connect_module (shared)
proxy_express_module (shared)
proxy_fcgi_module (shared)
proxy_fdpass_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_scgi_module (shared)
ssl_module (shared)
systemd_module (shared)
cgi_module (shared)
php5_module (shared)
evasive20_module (shared)
Run Code Online (Sandbox Code Playgroud)
apachectl -M
以上输出。知道什么可能导致这种情况吗?
我遇到了这个确切的问题,我不确定以下原因是否总是导致此错误(特别是在问题方式中描述的),但对我来说就是这种情况,所以我只是想分享我的想法。
Debian 7 喘息 (7.7),阿帕奇 2.2.2
当用户应该将消息的状态更改为已读/未读时,我正在制作一个功能,同时单击“链接”,当 ajax 被发送到服务器时,因此,在测试时 - 快速单击该链接以查看它是否有效很好(所以它不会是 2 个并发的 ajax 请求)我收到了这个错误
Forbidden
You don't have permission to access /messages on this server.
Run Code Online (Sandbox Code Playgroud)
奇怪的是,在此之前,有一些成功的ajax请求,路径正常,包括域名,如http://example.com/messages/changeStatus/11
. 这意味着代码没问题。但是,另一方面,如果我能等几秒钟再试一次,它会正常工作。
我安装了 mod-security 和 mod-evasive,所以在这个错误之后我从/var/log/apache2/modsec_audit.log
文件中找到了最后几行。
--ba0f4035-E--
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /messages/changeStatus/24
on this server.</p>
</body></html>
--ba0f4035-H--
Apache-Error: [file "mod_evasive20.c"] [line 246] [level 3] client denied by server configuration: /home/user_name/www/example/messages, referer: http://example.com/messages
Stopwatch: 1421177262896100 4724 (- - -)
Stopwatch2: 1421177262896100 4724; combined=10, p1=0, p2=0, p3=2, p4=0, p5=7, sr=0, sw=1, l=0, gc=0
Response-Body-Transformed: Dechunked
Producer: ModSecurity for Apache/2.6.6 (http://www.modsecurity.org/).
Server: Apache/2.2.22 (Debian) PHP/5.4.36-0+deb7u1 mod_ssl/2.2.27 OpenSSL/1.0.1h
--ba0f4035-Z--
Run Code Online (Sandbox Code Playgroud)
做更多的搜索,因为我在这篇文章中发现了日志的错误。 https://www.atomicorp.com/wiki/index.php/Mod_evasive
所以,mod evasive 是原因,因为它的默认参数太敏感,主要在/etc/apache2/mods-available/mod-evasive.conf
默认情况下在文件中我有这些选项
<ifmodule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
DOSLogDir /var/log/mod_evasive
DOSEmailNotify EMAIL@DOMAIN.com
DOSWhitelist 127.0.0.1
</ifmodule>
Run Code Online (Sandbox Code Playgroud)
正如我们从上面的链接中了解到的
MODEV_DOSPageCount - 这是每个页面间隔对同一页面(或 URI)的请求数量的阈值。一旦超过该间隔的阈值,客户端的 IP 地址将被添加到阻止列表中。
和
MODEV_DOSPageInterval - 页计数阈值的间隔;默认为 1 秒间隔。
因此,根据默认选项,如果我在 1 秒内对同一个 url 执行 2 个请求,它会显示 403 错误,这在我身上发生了:ASA 我将数字增加到 20,我已经无法复制错误消息.
在另一方面
MODEV_DOSBlockingPeriod 阻止周期是客户端被添加到阻止列表后将被阻止的时间量(以秒为单位)。在此期间,来自客户端的所有后续请求将导致 403(禁止)和计时器被重置(例如,另外 10 秒)。由于每次后续请求都会重置定时器,因此不需要很长的阻塞周期;如果发生 DoS 攻击,此计时器将不断重置
所以,正如我们所看到的,经过DOSBlockingPeriod
一段时间后,ip 将从黑名单中删除;因为我猜这就是原因,日志中没有禁止的 IP,而且,当几秒钟后单击 F5 时,它工作正常,因为阻止期已经过去。
我还用长阻塞周期和小页面计数值对此进行了测试,主要分别设置为 1000 和 1。在 2-3 个 ajax 请求之后,它开始显示 403 并且在几秒钟后没有消失。
希望这会帮助某人。
归档时间: |
|
查看次数: |
10456 次 |
最近记录: |