ops: Cache all electrs endpoints for minimum of 1s

This commit is contained in:
wiz 2024-11-01 21:14:57 +09:00
parent c0ef01d4da
commit 0a9703f164
No known key found for this signature in database
GPG Key ID: A394E332255A6173

View File

@ -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;