我的Apache 2.4(CentOS 7)服务器托pipe多个网站。 在访问任何网站文件(主要是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)
上面的apachectl -M输出。 任何想法可能会导致这一点?
我有这个确切的问题,我不知道下面的原因是什么总是导致这个错误(特别是在问题的方式描述),但这是我的情况,所以我只是想分享我的想法。
Debian 7 wheezy(7.7),apache 2.2.2
我正在做一个function,当用户应该改变消息的状态为读/未读,而点击一个“链接”,当一个AJAX发送到服务器,所以,在testing时 – 快速点击该链接,看看它是否工作罚款(所以它不会是2个并发的Ajax请求)我得到这个错误
Forbidden You don't have permission to access /messages on this server.
奇怪的是,在那之前,有一些成功的ajax请求,包括像http://example.com/messages/changeStatus/11这样的域名。 这意味着代码是好的。 但是,另一方面,如果我可以等待几秒钟,然后再试一次,那就可以正常工作了。
我安装了mod-security和mod-evasive,所以在发现这个错误之后,我从/var/log/apache2/modsec_audit.log文件中find了这些最后一行。
--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--
做更多的search,因为我发现在这篇文章中的日志的错误。 https://www.atomicorp.com/wiki/index.php/Mod_evasive
所以,mod是回避的原因,因为默认的params对它太敏感了,主要是在/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 protected] DOSWhitelist 127.0.0.1 </ifmodule>
正如我们从上面的链接中学到的
MODEV_DOSPageCount – 这是每个页面间隔对相同页面(或URI)的请求数量的阈值。 一旦超过该时间间隔的阈值,客户端的IP地址将被添加到阻止列表中。
和
MODEV_DOSPageInterval – 页数阈值的间隔; 默认为1秒的间隔。
所以,根据默认选项,如果我会在1秒内做同样的url2请求它会显示403错误,这是发生在我身上:我ASA增加到20,我已经无法复制错误消息。
在另一方面
MODEV_DOSBlockingPeriod阻塞时间段是客户端被添加到阻塞列表中的时间(以秒为单位)。 在此期间,来自客户端的所有后续请求将导致403(禁止)并且定时器被重置(例如,另外10秒)。 由于定时器对于每个后续请求都被重置,所以不需要具有很长的阻塞周期; 在发生DoS攻击时,此计时器将不断得到重置
所以,正如我们所看到的,在DOSBlockingPeriod时间过去之后,IP将从黑名单中删除; 正如我猜测这是原因,在日志中没有禁止的IP,也就是说,几秒钟后点击F5,它可以正常工作,因为封锁的时期已经过去了。
我也用长阻塞期和小页计数值来testing它,主要分别设置1000和1。 经过2-3个Ajax请求,它开始显示403,几秒钟后没有消失。
希望这会帮助别人。
你刚刚从2.2升级到2.4? 尝试从2.2升级到2.4 。
只是有这个相同的问题 – 除了mod_evasive没有安装。 我100%确定它没有安装或启用。
解决scheme是安装libapache2-mod-evasive然后禁用它。 也许它被合并到Apache核心?
服务器版本:Apache / 2.4.18(Ubuntu)服务器内置:2017-07-27T14:34:01