How to rate-limit api routes? #19
-
The following steps will guide you on how to rate-limit your self hosted supabase instance's api routes based on user's ip address with caddy server |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
1. Update environment variables:In
The above values will allow 2. Update caddy service config:In services:
caddy:
container_name: caddy-container
# 👇 UPDATED IMAGE. This is a caddy image built with caddy-ratelimit module. Repo: https://github.com/singh-inder/caddy-with-rate-limit
image: ghcr.io/singh-inder/caddy-with-rate-limit:v1.1.0
restart: unless-stopped
environment:
DOMAIN: ${SUPABASE_PUBLIC_URL:?error}
# 👇 pass env vars to container
CADDY_RATE_LIMIT_WINDOW: ${CADDY_RATE_LIMIT_WINDOW:?error}
CADDY_RATE_LIMIT_COUNT: ${CADDY_RATE_LIMIT_COUNT:?error}
ports:
- 80:80
- 443:443
- "443:443/udp"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- ./volumes/caddy/caddy_data:/data
- ./volumes/caddy/caddy_config:/config
# ... rest of the services 3. Update Caddyfile:Update If you've setup with authelia:
If you've setup with basic username/password auth:
|
Beta Was this translation helpful? Give feedback.
1. Update environment variables:
In
supabase-automated-self-host/docker/.env
file, add the following env vars:The above values will allow
80 requests/min
. You can adjust the rate limit window/rate limit count acc. to your needs.Take a look at these examples for supported time units for
CADDY_RATE_LIMIT_WINDOW
.2. Update caddy service config:
In
supabase-automated-self-host/docker/docker-compose.yml
file, update the caddy service config: