From 6b498b96011db9c6bbbfc223eb1443511b130355 Mon Sep 17 00:00:00 2001 From: wiz Date: Thu, 3 Dec 2020 09:47:39 +0900 Subject: [PATCH] Exempt localhost from nginx rate limits for Tor and AU usage --- production/nginx.conf | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/production/nginx.conf b/production/nginx.conf index f14aa0b1d..a92f86ae3 100644 --- a/production/nginx.conf +++ b/production/nginx.conf @@ -54,13 +54,23 @@ http { proxy_cache_path /var/cache/nginx keys_zone=cache:20m levels=1:2 inactive=600s max_size=500m; types_hash_max_size 2048; + # exempt localhost from rate limit + geo $limited_ip { + default 1; + 127.0.0.1 0; + } + map $limited_ip $limited_ip_key { + 1 $binary_remote_addr; + 0 ''; + } + # rate limit requests - limit_req_zone $binary_remote_addr zone=api:5m rate=200r/m; - limit_req_zone $binary_remote_addr zone=electrs:5m rate=2000r/m; + limit_req_zone $limited_ip_key zone=api:5m rate=200r/m; + limit_req_zone $limited_ip_key zone=electrs:5m rate=2000r/m; limit_req_status 429; # rate limit connections - limit_conn_zone $binary_remote_addr zone=websocket:10m; + limit_conn_zone $limited_ip_key zone=websocket:10m; limit_conn_status 429; map $http_accept_language $header_lang {