大网数据广告活动
服务器运维问答

How to ignore event source log

· 52CE 我爱测

I have an event source running regularly. The problem is that http-get-dos from fail2ban will catch the IP if the user left the tab open for a large amount of time. So , I am thinking, how can I disable this type of specific log …

问题原文

原帖链接 · Fel · CC BY-SA 4.0

I have an event source running regularly. The problem is that http-get-dos from fail2ban will catch the IP if the user left the tab open for a large amount of time.

So , I am thinking, how can I disable this type of specific log in ningx? The alternative is to configure fail2ban to ignore this pattern.

"GET /users/stream HTTP/2.0"

I am willing to implement in nginx or fail2ban.

Probably changing accordingly this line in /etc/fail2ban/filter.d/http-get-dos.conf is the most straightforward way:

failregex = ^<HOST> -.*"(GET|POST).*

Update (/etc/fail2ban/filter.d/http-get-dos.conf):

# Fail2Ban configuration file
[Definition]

# Option: failregex
# Note: This regex will match any GET entry in your logs, so basically all valid and not valid entries are a match.
# You should set up in the jail.conf file, the maxretry and findtime carefully in order to avoid false positives.
failregex = ^<HOST> -.*"(GET|POST).*
# Option: ignoreregex
ignoreregex =

##To stop DOS attack from remote host.
[http-get-dos]
enabled = true
port = http,https
filter = http-get-dos
logpath  = /usr/local/nginx/localhost-access.log
maxretry = 300
findtime = 300
bantime = 600
action = iptables[name=HTTP, port=http, protocol=tcp]

First try: Apparently not working with the regex below:

fail2ban-regex /usr/local/nginx/localhost-access.log '^<HOST> -.*"(GET|POST).*' '^.+?:\d+ <HOST> -.*"(GET) /users/stream.*$'

Running tests
=============

Use   failregex line : ^<HOST> -.*"(GET|POST).*
Use ignoreregex line : ^.+?:\d+ <HOST> -.*"(GET) /users/stream.*$
Use         log file : /usr/local/nginx/localhost-access.log
Use         encoding : UTF-8


Results
=======

Failregex: 22431 total
|-  #) [# of hits] regular expression
|   1) [22431] ^<HOST> -.*"(GET|POST).*
`-

Ignoreregex: 0 total

Second try: But will work with ^<HOST> -.*"(GET) /users/stream.*$

fail2ban-regex /usr/local/nginx/localhost-access.log '^<HOST> -.*"(GET|POST).*' '^<HOST> -.*"(GET) /users/stream.*$'

Running tests
=============

Use   failregex line : ^<HOST> -.*"(GET|POST).*
Use ignoreregex line : ^<HOST> -.*"(GET) /users/stream.*$
Use         log file : /usr/local/nginx/localhost-access.log
Use         encoding : UTF-8


Results
=======

Failregex: 1574 total
|-  #) [# of hits] regular expression
|   1) [1574] ^<HOST> -.*"(GET|POST).*
`-

Ignoreregex: 22093 total
|-  #) [# of hits] regular expression
|   1) [22093] ^<HOST> -.*"(GET) /users/stream.*$
`-

已采纳解答

原帖链接 · frontsidebus · CC BY-SA 4.0

You're on the right track using the

ignoreregex =

directive in your

/etc/fail2ban/filter.d/http-get-dos.conf

config file. This should just be a matter of tweaking the regex. Something like this:

^<HOST> -.*"(GET) /users/stream.*$

which matches your log file line, then matches for any GET's and only GET's with requests that have the /users/stream prefix, and any string appended to it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-12-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。