All Projects → limithit → Ngx_dynamic_limit_req_module

limithit / Ngx_dynamic_limit_req_module

Licence: gpl-3.0
The ngx_dynamic_limit_req_module module is used to dynamically lock IP and release it periodically.

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Ngx dynamic limit req module

Testcookie Nginx Module
simple robot mitigation module using cookie based challenge/response technique. Not supported any more.
Stars: ✭ 447 (+684.21%)
Mutual labels:  ddos, nginx, nginx-module
Huststore
High-performance Distributed Storage
Stars: ✭ 806 (+1314.04%)
Mutual labels:  redis, nginx
Photo Blog
The Photo Blog Application based on Laravel 5 and Vue.js 2 + Prerender
Stars: ✭ 55 (-3.51%)
Mutual labels:  redis, nginx
Springbootunity
rabbitmq、redis、scheduled、socket、mongodb、Swagger2、spring data jpa、Thymeleaf、freemarker etc. (muti module spring boot project) (with spring boot framework,different bussiness scence with different technology。)
Stars: ✭ 845 (+1382.46%)
Mutual labels:  redis, nginx
Wordops
Install and manage a high performance WordPress stack with a few keystrokes
Stars: ✭ 649 (+1038.6%)
Mutual labels:  redis, nginx
Filterlists
🛡 The independent, comprehensive directory of filter and host lists for advertisements, trackers, malware, and annoyances.
Stars: ✭ 653 (+1045.61%)
Mutual labels:  redis, nginx
Php Interview
PHP后端开发面试指南。
Stars: ✭ 26 (-54.39%)
Mutual labels:  redis, nginx
Bloom
🌸 HTTP REST API caching middleware, to be used between load balancers and REST API workers.
Stars: ✭ 553 (+870.18%)
Mutual labels:  redis, ddos
Nginx Cleantalk Service
LUA configuration to filter any POST requests.
Stars: ✭ 13 (-77.19%)
Mutual labels:  block, nginx
Wp Vps Build Guide
A verbose build guide for a modern, high-performance WordPress production VPS.
Stars: ✭ 31 (-45.61%)
Mutual labels:  redis, nginx
Docker Vue Node Nginx Mongodb Redis
🐉 An awesome boilerplate, Integrated Docker, Vue, Node, Nginx, Mongodb and Redis in one, Designed to develop & build your web applications more efficient and elegant.
Stars: ✭ 34 (-40.35%)
Mutual labels:  redis, nginx
Docker Alpine
Docker containers running Alpine Linux and s6 for process management. Solid, reliable containers.
Stars: ✭ 574 (+907.02%)
Mutual labels:  redis, nginx
Nginx Module Sysguard
Nginx sysguard module
Stars: ✭ 568 (+896.49%)
Mutual labels:  nginx, nginx-module
Lua Nginx Redis
🌺 Redis、Lua、Nginx、OpenResty 笔记和资料
Stars: ✭ 757 (+1228.07%)
Mutual labels:  redis, nginx-module
Centrifugo
Scalable real-time messaging server in a language-agnostic way. Set up once and forever.
Stars: ✭ 5,649 (+9810.53%)
Mutual labels:  redis, real-time
Nginx Nonewlines
This is an nginx module to strip the served HTML of all newlines (\n and \r characters)
Stars: ✭ 17 (-70.18%)
Mutual labels:  nginx, nginx-module
Drupal Nginx Php Kubernetes
Demonstration of a set of NGINX and PHP-FPM containers running Drupal deployed to Kubernetes on the IBM Container Service. This is a work in progress.
Stars: ✭ 43 (-24.56%)
Mutual labels:  redis, nginx
Centrifuge
Real-time messaging library for Go with scalability in mind
Stars: ✭ 446 (+682.46%)
Mutual labels:  redis, real-time
Blog
Jiajun的编程随想
Stars: ✭ 528 (+826.32%)
Mutual labels:  redis, nginx
Netkiller.github.io
Netkiller Free ebook - 免费电子书
Stars: ✭ 861 (+1410.53%)
Mutual labels:  redis, nginx

ngx_dynamic_limit_req_module

Introduction

The ngx_dynamic_limit_req_module module is used to dynamically lock IP and release it periodically.

Table of Contents

dynamic_limit_req_zone

Sets parameters for a shared memory zone that will keep states for various keys. In particular, the state stores the current number of excessive requests. The key can contain text, variables, and their combination. Requests with an empty key value are not accounted.

 Syntax:  dynamic_limit_req_zone key zone=name:size rate=rate [sync]  redis=127.0.0.1 block_second=time;
 Default: —
 Context: http

dynamic_limit_req_redis

Sets optional parameters, unix_socket, port, requirepass.

The socket must be accessible for nginx. You first have to change the chmod of the socket to 770 that the redis group can access it, make changes in /etc/redis/redis.conf: unixsocketperm 770 unixsocket /tmp/redis.sock and then add nginx to the redis group usermod -g redis nginx

 Syntax:  dynamic_limit_req_redis  unix_socket | port=[number] requirepass=[password];
 Default: port 6379
 Context: http

example:

dynamic_limit_req_zone $binary_remote_addr zone=sms:5m rate=5r/m redis=/tmp/redis.sock block_second=1800;
dynamic_limit_req zone=sms burst=3 nodelay;
dynamic_limit_req_redis unix_socket requirepass=comeback;

or required for non-standard ports, not required for standard port 6379

dynamic_limit_req_zone $binary_remote_addr zone=sms:5m rate=5r/m redis=127.0.0.1 block_second=1800;
dynamic_limit_req zone=sms burst=3 nodelay;
dynamic_limit_req_redis port=6378 requirepass=comeback;

dynamic_limit_req

Sets the shared memory zone and the maximum burst size of requests. If the requests rate exceeds the rate configured for a zone, their processing is delayed such that requests are processed at a defined rate. Excessive requests are delayed until their number exceeds the maximum burst size in which case the request is terminated with an error. By default, the maximum burst size is equal to zero.

 Syntax:  dynamic_limit_req zone=name [burst=number] [nodelay | delay=number];
 Default: —
 Context: http, server, location, if

dynamic_limit_req_log_level

Sets the desired logging level for cases when the server refuses to process requests due to rate exceeding, or delays request processing. Logging level for delays is one point less than for refusals; for example, if “dynamic_limit_req_log_level notice” is specified, delays are logged with the info level.

 Syntax:  dynamic_limit_req_log_level info | notice | warn | error;
 Default: dynamic_limit_req_log_level error;
 Context: http, server, location

dynamic_limit_req_status

Sets the status code to return in response to rejected requests.

 Syntax:  dynamic_limit_req_status code;
 Default: dynamic_limit_req_status 503;
 Context: http, server, location, if

Configuration example:

    worker_processes  2;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        
   dynamic_limit_req_zone $binary_remote_addr zone=one:10m rate=100r/s redis=127.0.0.1 block_second=300;
   dynamic_limit_req_zone $binary_remote_addr zone=two:10m rate=50r/s redis=127.0.0.1 block_second=600;
   dynamic_limit_req_zone $binary_remote_addr zone=sms:5m rate=5r/m redis=127.0.0.1 block_second=1800;
        
        
        server {
            listen       80;
            server_name  localhost;
            location / {
                
                if ($http_x_forwarded_for) {
                 return 400;
                }
                root   html;
                index  index.html index.htm;
                dynamic_limit_req zone=one burst=100 nodelay;
                dynamic_limit_req_status 403;
            }
            error_page   403 500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
        server {
            listen       80;
            server_name  localhost2;
            location / {
                root   html;
                index  index.html index.htm; 
                
                    set $flag 0;
                   if ($document_uri ~* "regist"){
                      set $flag "${flag}1";
                        }
                  if ($request_method = POST ) {
                        set $flag "${flag}2";
                          }
                      if ($flag = "012"){
                      dynamic_limit_req zone=sms burst=3 nodelay;
                      dynamic_limit_req_status 403;
                      }

                
                      if ($document_uri ~* "getSmsVerifyCode.do"){
                      dynamic_limit_req zone=sms burst=5 nodelay;
                      dynamic_limit_req_status 444;
                }

                dynamic_limit_req zone=two burst=50 nodelay;
                dynamic_limit_req_status 403;
            }
            error_page   403 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
   

If you use CDN at the source station :

 worker_processes  2;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        
       ####--with-http_realip_module  
       
       set_real_ip_from 192.168.16.0/24;
       real_ip_header X-Forwarded-For;
       real_ip_recursive on;
        
   #### $http_x_forwarded_for or $binary_remote_addr
  dynamic_limit_req_zone $http_x_forwarded_for zone=one:10m rate=100r/s redis=127.0.0.1 block_second=300;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
                dynamic_limit_req zone=one burst=100 nodelay;
                dynamic_limit_req_status 403;
            }
            error_page   403 500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }

    }

About ngx_http_realip_module

black-and-white-list

White list rules

redis-cli set whiteip ip

example: redis-cli set white192.168.1.1 192.168.1.1

Black list rules

redis-cli set ip ip

example: redis-cli set 192.168.1.2 192.168.1.2

Installation

Option #1: Compile Nginx with module bundled

cd redis-4.0**version**/deps/hiredis
make 
make install 
echo /usr/local/lib >> /etc/ld.so.conf
ldconfig

cd nginx-**version**
./configure --add-module=/path/to/this/ngx_dynamic_limit_req_module 
make
make install

Option #2: Compile dynamic module for Nginx

Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the --add-dynamic-module=PATH option instead of --add-module=PATH on the ./configure command line above. And then you can explicitly load the module in your nginx.conf via the load_module directive, for example,

    load_module /path/to/modules/ngx_dynamic_limit_req_module.so;

principle

The ngx_dynamic_limit_req_module module is used to limit the request processing rate per a defined key, in particular, the processing rate of requests coming from a single IP address. The limitation is done using the “leaky bucket” method.

About

This module is an extension based on ngx_http_limit_req_module.

Donate

The developers work tirelessly to improve and develop ngx_dynamic_limit_req_module. Many hours have been put in to provide the software as it is today, but this is an extremely time-consuming process with no financial reward. If you enjoy using the software, please consider donating to the devs, so they can spend more time implementing improvements.

Alipay:

Alipay

Extend

This module can be works with RedisPushIptables, the application layer matches then the network layer to intercept. Although network layer interception will save resources, there are also deficiencies. Assuming that only one specific interface is filtered and no other interfaces are filtered, those that do not need to be filtered will also be inaccessible. Although precise control is not possible at the network layer or the transport layer, it can be precisely controlled at the application layer. Users need to weigh which solution is more suitable for the event at the time.

Api-count

If you want to use the api counting function, please use limithit-API_alerts. Because not everyone needs this feature, so it doesn't merge into the trunk. Users who do not need this feature can skip this paragraph description.

git clone https://github.com/limithit/ngx_dynamic_limit_req_module.git
cd ngx_dynamic_limit_req_module
git checkout limithit-API_alerts
[email protected]:~# redis-cli 
127.0.0.1:6379> SELECT 3
127.0.0.1:6379[3]> scan 0 match *12/Dec/2018* count 10000 
127.0.0.1:6379[3]> scan 0 match *PV count 10000
1) "0"
2) 1) "[13/Dec/2018]PV"
   2) "[12/Dec/2018]PV"
127.0.0.1:6379[3]> get [12/Dec/2018]PV
"9144"
127.0.0.1:6379[3]> get [13/Dec/2018]PV
"8066"
127.0.0.1:6379[3]> get [13/Dec/2018]UV
"214"

This module is compatible with following nginx releases:

Author Gandalf [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].