mempool/production/nginx/location-api.conf
2024-02-27 11:46:14 +09:00

185 lines
4.2 KiB
Plaintext

###########
# mempool #
###########
# Block the internal APIs of esplora
location /api/internal/ {
if ($mempool_external) {
return 403;
}
rewrite ^/api/(.*) /$1 break;
try_files /dev/null @esplora-api-cache-disabled;
}
location /api/v1/internal/ {
if ($mempool_external) {
return 403;
}
try_files /dev/null @mempool-api-v1-cache-normal;
}
# websocket has special HTTP headers
location /api/v1/ws {
try_files /dev/null @mempool-api-v1-websocket;
}
# warm cache mining and mempool API responses
location /api/v1/statistics {
try_files /dev/null @mempool-api-v1-cache-warm;
}
location /api/v1/mining {
try_files /dev/null @mempool-api-v1-cache-warm;
}
location /api/v1/fees/recommended {
try_files /dev/null @mempool-api-v1-cache-hot;
}
# it's ok to cache blockchain data "forever", so we do 30d
location /api/v1/block/ {
try_files /dev/null @mempool-api-v1-cache-forever;
}
# everything else gets "normal" cache
location /api/v1 {
try_files /dev/null @mempool-api-v1-cache-normal;
}
###########
# esplora #
###########
# it's ok to cache blockchain data "forever", so we do 30d
location /api/block/ {
rewrite ^/api/(.*) /$1 break;
try_files /dev/null @esplora-api-cache-forever;
}
# other API responses cannot be cached
location /api/ {
rewrite ^/api/(.*) /$1 break;
try_files /dev/null @esplora-api-cache-disabled;
}
###########
# routing #
###########
location @mempool-api-v1-websocket {
proxy_pass $mempoolMainnet;
proxy_http_version 1.1;
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 Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-Proto $scheme;
}
location @mempool-api-v1-cache-forever {
proxy_pass $mempoolMainnet;
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 apicold;
proxy_cache_valid 200 30d;
proxy_redirect off;
expires 30d;
}
location @mempool-api-v1-cache-hot {
proxy_pass $mempoolMainnet;
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 @mempool-api-v1-cache-warm {
proxy_pass $mempoolMainnet;
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 apiwarm;
proxy_cache_valid 200 10s;
proxy_redirect off;
}
location @mempool-api-v1-cache-normal {
proxy_pass $mempoolMainnet;
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 apinormal;
proxy_cache_valid 200 2s;
proxy_redirect off;
expires 2s;
}
location @mempool-api-v1-cache-disabled {
proxy_pass $mempoolMainnet;
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_redirect off;
proxy_buffering off;
expires -1;
}
location @esplora-api-cache-disabled {
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_redirect off;
proxy_buffering off;
expires -1;
}
location @esplora-api-cache-forever {
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 apicold;
proxy_cache_valid 200 30d;
proxy_redirect off;
expires 30d;
}