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; +}