diff --git a/production/nginx-cache-warmer b/production/nginx-cache-warmer new file mode 100755 index 000000000..48812af58 --- /dev/null +++ b/production/nginx-cache-warmer @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh +hostname=$(hostname) +while true +do for url in /url/v1/statistics/2h \ + /url/v1/statistics/24h \ + /url/v1/statistics/1w \ + /url/v1/statistics/1m \ + /url/v1/statistics/3m \ + /url/v1/statistics/6m \ + /url/v1/statistics/1y \ + /url/v1/statistics/2y \ + /url/v1/statistics/3y \ + / + do + curl -s "https://${hostname}${url}" >/dev/null + done + + sleep 10 +done diff --git a/production/nginx/http-proxy-cache.conf b/production/nginx/http-proxy-cache.conf index 84efabffc..f870939b3 100644 --- a/production/nginx/http-proxy-cache.conf +++ b/production/nginx/http-proxy-cache.conf @@ -1,4 +1,5 @@ # proxy cache +proxy_cache_path /var/cache/nginx/api keys_zone=api:20m levels=1:2 inactive=600s max_size=100m; proxy_cache_path /var/cache/nginx/services keys_zone=services:20m levels=1:2 inactive=600s max_size=100m; proxy_cache_path /var/cache/nginx/markets keys_zone=markets:20m levels=1:2 inactive=600s max_size=100m; types_hash_max_size 2048; diff --git a/production/nginx/location-api.conf b/production/nginx/location-api.conf index bf869f70d..67b77a714 100644 --- a/production/nginx/location-api.conf +++ b/production/nginx/location-api.conf @@ -1,15 +1,15 @@ location /api/v1/statistics { - try_files /dev/null @mempool-api-v1-cache; + try_files /dev/null @mempool-api-v1-warmcache; } location /api/v1 { - try_files /dev/null @mempool-api-v1-nocache; + try_files /dev/null @mempool-api-v1-coldcache; } location /api/ { rewrite ^/api/(.*) /$1 break; try_files /dev/null @electrs-api-nocache; } -location @mempool-api-v1-cache { +location @mempool-api-v1-warmcache { proxy_pass $mempoolBackend; proxy_http_version 1.1; @@ -21,10 +21,29 @@ location @mempool-api-v1-cache { proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; + proxy_cache_background_update on; + proxy_cache_use_stale updating; + proxy_cache api; + proxy_cache_valid 200 10s; proxy_redirect off; - proxy_buffering off; + expires 10s; +} - proxy_cache_valid any 10s; +location @mempool-api-v1-coldcache { + proxy_pass $mempoolBackend; + proxy_http_version 1.1; + + proxy_set_header Host $http_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; + + proxy_cache_bypass $http_upgrade; + proxy_cache api; + proxy_cache_valid 200 10s; + proxy_redirect off; expires 10s; }