Program Club

Apache로 속도 제한을 어떻게 구현할 수 있습니까?

proclub 2020. 10. 12. 08:20
반응형

Apache로 속도 제한을 어떻게 구현할 수 있습니까? (초당 요청)


Apache에서 강력한 속도 제한 (requests | bytes / ip / unit time)을 구현하는 데 사용할 수있는 기술 및 / 또는 모듈은 무엇입니까?


최고

  • mod_evasive (DoS 노출 감소에 더 중점을 둡니다)
  • mod_cband ( '일반'대역폭 제어에 가장 적합 함)

그리고 그 나머지


이 블로그 게시물 에서 언급했듯이 mod_security사용 하여 초당 속도 제한을 구현하는 것이 가능해 보입니다 .

구성은 다음과 같습니다.

SecRuleEngine On

<LocationMatch "^/somepath">
  SecAction initcol:ip=%{REMOTE_ADDR},pass,nolog
  SecAction "phase:5,deprecatevar:ip.somepathcounter=1/1,pass,nolog"
  SecRule IP:SOMEPATHCOUNTER "@gt 60" "phase:2,pause:300,deny,status:509,setenv:RATELIMITED,skip:1,nolog"
  SecAction "phase:2,pass,setvar:ip.somepathcounter=+1,nolog"
  Header always set Retry-After "10" env=RATELIMITED
</LocationMatch>

ErrorDocument 509 "Rate Limit Exceeded"

웹 애플리케이션 방화벽을 포함한 다양한 방법이 있지만 Apache 모드를 사용하는 경우 구현하기 가장 쉬운 방법입니다.

제가 추천하고 싶은 모드 중 하나는 mod_qos 입니다. certin DOS, Bruteforce 및 Slowloris 유형 공격에 대해 매우 효과적인 무료 모듈입니다. 이렇게하면 서버로드가 상당히 완화됩니다.

그것은 매우 강력 합니다.

mod_qos 모듈 의 현재 릴리스는 다음 을 관리하기위한 제어 메커니즘을 구현합니다.

  • 위치 / 리소스 (URL) 또는 가상 호스트에 대한 최대 동시 요청 수입니다.

  • URL에 대한 초당 최대 허용 요청 수 또는 초당 다운로드 된 최대 / 최소 KB와 같은 대역폭의 제한.

  • 초당 요청 이벤트 수를 제한합니다 (특수 요청 조건).

  • 정의 된 기간 내 요청 이벤트 수를 제한합니다.
  • 또한 제한없이 또는 제한없이 웹 서버에 액세스 할 수있는 매우 중요한 사람 (VIP)을 감지 할 수 있습니다.
  • 무단 작업을 거부하는 일반 요청 라인 및 헤더 필터.

  • 본문 데이터 제한 및 필터링을 요청합니다 (mod_parp 필요).

  • 개별 클라이언트 (IP)에 대한 요청 이벤트 수를 제한합니다.

  • TCP 연결 수준에 대한 제한 (예 : 단일 IP 소스 주소 또는 동적 연결 유지 제어에서 허용되는 최대 연결 수).

  • 서버에 사용 가능한 TCP 연결이 부족할 때 알려진 IP 주소를 선호합니다.

이것은 사용할 수있는 샘플 구성입니다. 사용자의 요구에 맞는 수백 가지 가능한 구성이 있습니다. 컨트롤에 대한 자세한 정보는 사이트를 방문하십시오.

Sample configuration:
# minimum request rate (bytes/sec at request reading):
QS_SrvRequestRate                                 120

# limits the connections for this virtual host:
QS_SrvMaxConn                                     800

# allows keep-alive support till the server reaches 600 connections:
QS_SrvMaxConnClose                                600

# allows max 50 connections from a single ip address:
QS_SrvMaxConnPerIP                                 50

# disables connection restrictions for certain clients:
QS_SrvMaxConnExcludeIP                    172.18.3.32
QS_SrvMaxConnExcludeIP                    192.168.10.

http://opensource.adnovum.ch/mod_qos/


In Apache 2.4, there's a new stock module called mod_ratelimit. For emulating modem speeds, you can use mod_dialup. Though I don't see why you just couldn't use mod_ratelimit for everything.


Sadly, mod_evasive won't work as expected when used in non-prefork configurations (recent apache setups are mainly MPM)


One more option - mod_qos

Not simple to configure - but powerful.

http://opensource.adnovum.ch/mod_qos/


Depends on why you want to rate limit.

If it's to protect against overloading the server, it actually makes sense to put NGINX in front of it, and configure rate limiting there. It makes sense because NGINX uses much less resources, something like a few MB per ten thousand connections. So, if the server is flooded, NGINX will do the rate limiting(using an insignificant amount of resources) and only pass the allowed traffic to Apache.

If all you're after is simplicity, then use something like mod_evasive.

As usual, if it's to protect against DDoS or DoS attacks, use a service like Cloudflare which also has rate limiting.

참고URL : https://stackoverflow.com/questions/131681/how-can-i-implement-rate-limiting-with-apache-requests-per-second

반응형