diff --git a/production/nginx/http-proxy-cache.conf b/production/nginx/http-proxy-cache.conf index f870939b3..4d0e6614e 100644 --- a/production/nginx/http-proxy-cache.conf +++ b/production/nginx/http-proxy-cache.conf @@ -1,5 +1,7 @@ # 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; +proxy_cache_path /var/cache/nginx/api keys_zone=api:20m levels=1:2 inactive=600s max_size=200m; +proxy_cache_path /var/cache/nginx/services keys_zone=services:20m levels=1:2 inactive=600s max_size=200m; +proxy_cache_path /var/cache/nginx/markets keys_zone=markets:20m levels=1:2 inactive=600s max_size=200m; +proxy_cache_path /var/cache/nginx/unfurler keys_zone=unfurler:20m levels=1:2 inactive=600s max_size=200m; +proxy_cache_path /var/cache/nginx/slurper keys_zone=slurper:20m levels=1:2 inactive=600s max_size=200m; types_hash_max_size 2048; diff --git a/production/nginx/nginx.conf b/production/nginx/nginx.conf index 5861067e8..c08005d14 100644 --- a/production/nginx/nginx.conf +++ b/production/nginx/nginx.conf @@ -23,8 +23,8 @@ http { include mempool/production/nginx/http-language.conf; # match preview/unfurl bot user-agents - map $http_user_agent $unfurlbot { - default 0; + map $http_user_agent $unfurlprefix { + default ""; } # mempool configuration diff --git a/production/nginx/server-common.conf b/production/nginx/server-common.conf index 68f3b6971..3406e3450 100644 --- a/production/nginx/server-common.conf +++ b/production/nginx/server-common.conf @@ -48,8 +48,8 @@ add_header Vary Cookie; # for exact / requests, redirect based on $lang # cache redirect for 5 minutes location = / { - if ($unfurlbot) { - proxy_pass $mempoolSpaceUnfurler; + if ($unfurlprefix != '') { + rewrite ^(.*)$ $unfurlprefix$1 last; } if ($lang != '') { return 302 $scheme://$host/$lang/; @@ -65,15 +65,15 @@ location ~ ^/([a-z][a-z])/(.+\..+\.(js|css))$ { } # cache everything else for 5 minutes location ~ ^/([a-z][a-z])$ { - if ($unfurlbot) { - proxy_pass $mempoolSpaceUnfurler; + if ($unfurlprefix != '') { + rewrite ^(.*)$ $unfurlprefix$1 last; } try_files $uri /$1/index.html /en-US/index.html =404; expires 5m; } location ~ ^/([a-z][a-z])/ { - if ($unfurlbot) { - proxy_pass $mempoolSpaceUnfurler; + if ($unfurlprefix != '') { + rewrite ^(.*)$ $unfurlprefix$1 last; } try_files $uri /$1/index.html /en-US/index.html =404; expires 5m; @@ -104,16 +104,53 @@ location /preview { } # unfurl renderer location ^~ /render { - proxy_pass $mempoolSpaceUnfurler; + try_files /dev/null @mempool-space-unfurler; expires 10m; } +# unfurl handler +location /unfurl/ { + try_files /dev/null @mempool-space-unfurler; +} +location /slurp/ { + try_files /dev/null @mempool-space-slurper; +} # catch-all for all URLs i.e. /address/foo /tx/foo /block/000 # cache 5 minutes since they change frequently location / { - if ($unfurlbot) { - proxy_pass $mempoolSpaceUnfurler; + if ($unfurlprefix != '') { + rewrite ^(.*)$ $unfurlprefix$1 last; } try_files /$lang/$uri $uri /en-US/$uri /en-US/index.html =404; expires 5m; } + +location @mempool-space-unfurler { + proxy_pass $mempoolSpaceUnfurler; + + 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 unfurler; + proxy_cache_valid 200 10m; + proxy_redirect off; +} + +location @mempool-space-slurper { + proxy_pass $mempoolSpaceUnfurler; + + 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 slurper; + proxy_cache_valid 200 10m; + proxy_redirect off; +}