← Home

Dokku uses NGINX by default, which supports rate limiting out-of-the box. This is how to customize the default nginx.conf.To rate limit paths with Dokku, you need to adjust the template of the nginx.conf file. Customizing the nginx.conf directly doesn't work because Dokku overwrites it on deploy.

Copy the default nginx.conf template and create a new file nginx.conf.sigil in the app root. Dokku will use this template to create the nginx.conf for this app.

Add the limit_req_zone directive, make sure it's outside the range loop:

limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;

{{ range $port_map := .PROXY_PORT_MAP | split " " }}
{{ $port_map_list := $port_map | split ":" }}
{{ $scheme := index $port_map_list 0 }}
{{ $listen_port := index $port_map_list 1 }}
{{ $upstream_port := index $port_map_list 2 }}

# ...

Add the limit_req directives to the paths that you want to rate limit. In my case, there were 2 root paths.

location    / {
    limit_req zone=one burst=20;

# ...

For my app, I need a little bit of burstiness. Consult the NGINX documentation to learn about both directives.

Deploy the app, Dokku should use the template to create the custom nginx.conf which rate limits your paths.

← Home

Erben Systems GmbH

Watterstrasse 81, c/o Sarbach Treuhand AG, 8105 Regensdorf, Switzerland

CHE-174.268.027 MwSt