Git Product home page Git Product logo

caddy-rate-limit's Introduction

caddy-rate-limit

a rate limit plugin for caddy

Travis CI Go Report Card GoDoc

Syntax

Excessive requests will be terminated with an error 429 (Too Many Requests)! And X-RateLimit-RetryAfter header will be returned.

For single resource:

ratelimit methods path rate burst unit
  • methods are the request methods it will match (comma separately)

  • path is the file or directory to apply rate limit

  • rate is the limited request in every time unit (r/s, r/m, r/h, r/d, r/w) (e.g. 1)

  • burst is the maximum burst size client can exceed; burst >= rate (e.g. 2)

  • unit is the time interval (currently support: second, minute, hour, day, week)

For multiple resources:

ratelimit methods rate burst unit {
    whitelist CIDR,CIDR
    status xxx,xxx
    resources
}
  • whitelist is the keyword for whitelist your trusted ips (comma separately). CIDR is the IP range you don't want to perform rate limit. whitelist is a general rule, it won't target for specific resource.
  • status is the keyword for matching the response status code (comma separately). If this rule is triggered, all subsequent requests from that client will be blocked regardless of which status code is returned or which resource is requested. Note: this won't block resources not defined in ratelimit's config.
  • resources is a list of files/directories to apply rate limit, one per line

Note: If you don't want to apply rate limit on some special resources, add ^ in front of the path.

Examples

Limit clients to 2 requests per second (bursts of 3) to any methods and any resources under /r:

ratelimit * /r 2 3 second

Don't perform rate limit if requests come from 1.2.3.4 or 192.168.1.0/30(192.168.1.0 ~ 192.168.1.3), for the listed paths, limit clients to 2 requests per minute (bursts of 2) if the request method is GET or POST and always ignore /dist/app.js:

ratelimit get,post 2 2 minute {
    whitelist 1.2.3.4/32,192.168.1.0/30
    status *
    /foo.html
    /api
    ^/dist/app.js
}

Download

curl https://getcaddy.com | bash -s personal http.ratelimit

Docker

docker run -d -p 2016:2016 -v `pwd`/Caddyfile:/go/src/github.com/xuqingfeng/caddy-rate-limit/Caddyfile --name ratelimit xuqingfeng/caddy-rate-limit

Inspired by

http://nginx.org/en/docs/http/ngx_http_limit_req_module.html

https://github.com/didip/tollbooth

caddy-rate-limit's People

Contributors

htfy96 avatar xuqingfeng avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.