From e75f913af3229be2ca9d26bbd26e16bb53f33f88 Mon Sep 17 00:00:00 2001 From: wiz Date: Fri, 1 Nov 2024 21:20:54 +0900 Subject: [PATCH] ops: Cache testnet electrs endpoints for minimum of 1s --- production/nginx/location-testnet-api.conf | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/production/nginx/location-testnet-api.conf b/production/nginx/location-testnet-api.conf index 86cc643a3..d43a51ce5 100644 --- a/production/nginx/location-testnet-api.conf +++ b/production/nginx/location-testnet-api.conf @@ -47,10 +47,10 @@ location /testnet/api/block/ { rewrite ^/testnet/api/(.*) /$1 break; try_files /dev/null @esplora-testnet-api-cache-forever; } -# other API responses cannot be cached +# we cache for 1s to mitigate DoS attacks location /testnet/api/ { rewrite ^/testnet/api/(.*) /$1 break; - try_files /dev/null @esplora-testnet-api-cache-disabled; + try_files /dev/null @esplora-testnet-api-cache-minimal; } ########### @@ -160,3 +160,20 @@ location @esplora-testnet-api-cache-forever { expires 30d; } + +location @esplora-testnet-api-cache-minimal { + proxy_pass $esploraTestnet; + + 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 off; + proxy_cache_use_stale error; + proxy_cache apihot; + proxy_cache_valid 200 1s; + proxy_redirect off; + + expires 1s; +}