From 0a9703f16453e4dad5e796527329cd1a340c5301 Mon Sep 17 00:00:00 2001 From: wiz Date: Fri, 1 Nov 2024 21:14:57 +0900 Subject: [PATCH] ops: Cache all electrs endpoints for minimum of 1s --- production/nginx/location-api.conf | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/production/nginx/location-api.conf b/production/nginx/location-api.conf index 70d6d7568..80f513147 100644 --- a/production/nginx/location-api.conf +++ b/production/nginx/location-api.conf @@ -55,10 +55,10 @@ location /api/block/ { rewrite ^/api/(.*) /$1 break; try_files /dev/null @esplora-api-cache-forever; } -# other API responses cannot be cached +# we cache for 1s to mitigate DoS attacks location /api/ { rewrite ^/api/(.*) /$1 break; - try_files /dev/null @esplora-api-cache-disabled; + try_files /dev/null @esplora-api-cache-minimal; } ########### @@ -171,6 +171,23 @@ location @esplora-api-cache-disabled { expires -1; } +location @esplora-api-cache-minimal { + proxy_pass $esploraMainnet; + + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + + proxy_cache_background_update on; + proxy_cache_use_stale updating; + proxy_cache apihot; + proxy_cache_valid 200 1s; + proxy_redirect off; + + expires 1s; +} + location @esplora-api-cache-forever { proxy_pass $esploraMainnet;