{"id":236859,"date":"2014-09-16T13:03:10","date_gmt":"2014-09-16T09:03:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=236859"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=236859","title":{"rendered":"<span class=\"post_title\">Fail2ban \u0438 nginx: \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u043c\u0443 URL<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a!<\/p>\n<p>  \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u0439. \u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0435\u0442\u044c \u043f\u043e\u043f\u0430\u043b\u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430\u043c\u0438 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u044f\u0449\u0438\u043a\u043e\u0432 \u0438 \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u043a \u043d\u0438\u043c. \u041f\u043e\u0441\u043b\u0435 \u0431\u0430\u043d\u0430 \u0432 iptables \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u0438 \u0441 \u0431\u041e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0431\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e. \u041a\u0430\u043a \u0431\u044b\u043b\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n<p>  <a name=\"habracut\"><\/a><i>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u0433\u043e-\u0442\u043e \u043d\u0438\u0436\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u00ab\u043f\u0440\u043e\u043f\u0438\u0441\u043d\u044b\u0435 \u0438\u0441\u0442\u0438\u043d\u044b\u00bb, \u043d\u043e \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b fail2ban \u0431\u044b\u043b \u0432 \u043d\u043e\u0432\u0438\u043d\u043a\u0443 \u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043c\u043e\u0433. \u041d\u0438\u0436\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u00abhow-to\u00bb \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e \u0434\u043b\u044f redhat-based-linux, \u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u043f\u043e\u0434 \u043b\u044e\u0431\u043e\u0439 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432.<\/i><\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d rpmforge, \u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"bash\">wget http:\/\/pkgs.repoforge.org\/rpmforge-release\/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm rpm --import http:\/\/apt.sw.be\/RPM-GPG-KEY.dag.txt rpm -i rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0432 nginx <a href=\"http:\/\/nginx.org\/ru\/docs\/http\/ngx_http_limit_req_module.html\">limit_req<\/a> \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e http{}  <\/p>\n<pre><code class=\"nginx\">limit_req_zone $binary_remote_addr zone=one:10m rate=5r\/s; <\/code><\/pre>\n<p>  \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u043e\u043d\u044b \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u043e, \u0432 \u0441\u043f\u0440\u0430\u0432\u043a\u0435 \u043a \u043c\u043e\u0434\u0443\u043b\u044e \u043e\u043d\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u044b.<\/p>\n<p>  \u0412 \u0441\u0435\u043a\u0446\u0438\u044e server{} \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c location, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0437\u0430\u0445\u0432\u0430\u0442\u044b\u0432\u0430\u0435\u0442 url, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0439 \u0442\u0440\u0430\u0444\u0438\u043a (\u0432 \u043c\u043e\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u044d\u0442\u043e \/auth\/):  <\/p>\n<pre><code class=\"nginx\">location \/auth\/ {     limit_req zone=one burst=10 nodelay;     try_files $uri \/index.php?q=$uri&$args; } <\/code><\/pre>\n<p>  \u0418\u043b\u0438, \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443, \u0434\u043b\u044f wordpress:  <\/p>\n<pre><code class=\"nginx\">location = \/wp-login.php {     limit_req zone=one burst=10 nodelay;     include fastcgi_params;     fastcgi_pass 127.0.0.1:9000; } <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0447\u0442\u043e \u043d\u0438\u0433\u0434\u0435 \u043d\u0435 \u043e\u0448\u0438\u0431\u043b\u0438\u0441\u044c \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c nginx:  <\/p>\n<pre><code class=\"bash\">nginx -t && service nginx restart <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0438 \u0432\u0440\u0435\u0434\u043e\u043d\u043e\u0441\u043d\u044b\u0439 \u0442\u0440\u0430\u0444\u0438\u043a \u0432\u0441\u0435 \u0435\u0449\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440, \u0442\u043e \u0432 error-\u043b\u043e\u0433 nignx&#8217;\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u0438\u0434\u0430:  <\/p>\n<pre><code class=\"nginx\">2014\/09\/11 02:15:11 [error] 17515#0: *1977466 limiting requests, excess: 10.540 by zone &quot;one&quot;, client: 93.170.112.10, server: \u0425\u0425\u0425, request: &quot;GET \/auth\/\u0425\u0425\u0425\u0425 HTTP\/1.1&quot;, host: &quot;\u0425\u0425\u0425&quot; <\/code><\/pre>\n<p>  \u042d\u0442\u043e \u0437\u043d\u0430\u0447\u0438\u0442, \u0447\u0442\u043e \u043b\u0438\u043c\u0438\u0442\u044b \u043d\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0441\u0435\u043a\u0443\u043d\u0434\u0443 \u0434\u043b\u044f \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u043e\u0432 \u043d\u0430\u0447\u0430\u043b\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c.<br \/>  \u0414\u0430\u043b\u0435\u0435 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0435 \u2014 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c fail2ban:  <\/p>\n<pre><code class=\"bash\">yum install fail2ban -y <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0412\u0430\u0448\u0438\u043c \u043b\u044e\u0431\u0438\u043c\u044b\u043c \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u043e\u043c \u0444\u0430\u0439\u043b \/etc\/fail2ban\/filter.d\/nginx-req-limit.conf \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c:  <\/p>\n<pre><code class=\"nginx\">[Definition] failregex = limiting requests, excess:.* by zone.*client: &lt;HOST&gt; ignoreregex = <\/code><\/pre>\n<p>  \u0411\u0435\u0440\u0435\u043c \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u044b\u0439 jail.conf  <\/p>\n<pre><code class=\"bash\">cp \/etc\/fail2ban\/jail.conf \/etc\/fail2ban\/jail.local <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043a\u043e\u043d\u0435\u0446:  <\/p>\n<pre><code class=\"nginx\">[nginx-req-limit]  enabled = true filter = nginx-req-limit action = iptables-multiport[name=ReqLimit, port=&quot;http,https&quot;, protocol=tcp] logpath = \/var\/log\/nginx\/*error.log findtime = 600 bantime = 7200 maxretry = 10 <\/code><\/pre>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u0431\u0435\u0440\u0438\u0442\u0435 \u043f\u043e\u0434 \u0441\u0435\u0431\u044f, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e \u043d\u0438\u0445 <a href=\"http:\/\/www.fail2ban.org\/wiki\/index.php\/MANUAL_0_8\">\u0442\u0443\u0442<\/a><br \/>  \u0420\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \/etc\/fail2ban\/action.d\/sendmail.conf, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0432 dest \u0438 sender \u043d\u0443\u0436\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430 (\u043e\u0442\u0441\u044b\u043b\u0430\u0442\u044c \u043f\u043e\u0447\u0442\u0443 \u0431\u0443\u0434\u0435\u0442, \u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0435\u0441\u0442\u044c \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 sendmail)<br \/>  \u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c fail2ban:  <\/p>\n<pre><code class=\"bash\">service fail2ban start <\/code><\/pre>\n<p>  \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0432 \u043b\u043e\u0433:<br \/>  tail -f \/var\/log\/fail2ban.log<br \/>  \u0415\u0441\u043b\u0438 \u0435\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u0438\u0434\u0430:  <\/p>\n<pre><code class=\"bash\">2014-09-10 21:32:20,575 fail2ban.actions: WARNING [nginx-req-limit] Ban 178.92.194.221 2014-09-10 21:37:33,136 fail2ban.actions: WARNING [nginx-req-limit] Ban 37.144.59.125 <\/code><\/pre>\n<p>  \u0437\u043d\u0430\u0447\u0438\u0442 \u0432\u0441\u0435 \u0438\u0434\u0435\u0442 \u043a\u0430\u043a \u043d\u0430\u0434\u043e \u0438 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u0431\u0430\u043d.<\/p>\n<p>  PROFIT!<\/p>\n<p>  P.S. \u0410 \u043a\u0430\u043a fail2ban \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0435 \u0412\u044b?:)      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/236859\/\"> http:\/\/habrahabr.ru\/post\/236859\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a!<\/p>\n<p>  \u041d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043d\u0435\u0439 \u043d\u0430\u0437\u0430\u0434 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0438\u0437 \u0441\u0432\u043e\u0438\u0445 \u0441\u0430\u0439\u0442\u043e\u0432 \u0437\u0430\u043c\u0435\u0442\u0438\u043b \u043f\u043e\u0434\u043e\u0437\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0431\u043e\u0440\u043e\u043c \u043f\u0430\u0440\u043e\u043b\u0435\u0439. \u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e \u044d\u0442\u043e \u043a\u0430\u043a \u0440\u0430\u0437 \u0442\u043e\u0433\u0434\u0430, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0441\u0435\u0442\u044c \u043f\u043e\u043f\u0430\u043b\u0438 \u0444\u0430\u0439\u043b\u044b \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430\u043c\u0438 \u043f\u043e\u0447\u0442\u043e\u0432\u044b\u0445 \u044f\u0449\u0438\u043a\u043e\u0432 \u0438 \u043f\u0430\u0440\u043e\u043b\u0435\u0439 \u043a \u043d\u0438\u043c. \u041f\u043e\u0441\u043b\u0435 \u0431\u0430\u043d\u0430 \u0432 iptables \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0437\u043b\u043e\u0443\u043c\u044b\u0448\u043b\u0435\u043d\u043d\u0438\u043a\u0438 \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u043e\u0434\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u043e\u043b\u0438 \u0441 \u0431\u041e\u043b\u044c\u0448\u0435\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0438 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0431\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0443\u0436\u0435 \u0441\u0442\u0430\u043b\u043e \u043d\u0435\u0443\u0434\u043e\u0431\u043d\u043e. \u041a\u0430\u043a \u0431\u044b\u043b\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u044d\u0442\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u043e\u0434 \u043a\u0430\u0442\u043e\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-236859","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/236859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236859"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/236859\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}