ops: Add nginx config for /unfurler and /slurper prefixes

This commit is contained in:
wiz 2023-08-16 03:27:09 +09:00
parent 13f6f9f9e5
commit 83a92a7e3a
No known key found for this signature in database
GPG key ID: A394E332255A6173
3 changed files with 53 additions and 14 deletions

View file

@ -1,5 +1,7 @@
# proxy cache # 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/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=100m; 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=100m; 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; types_hash_max_size 2048;

View file

@ -23,8 +23,8 @@ http {
include mempool/production/nginx/http-language.conf; include mempool/production/nginx/http-language.conf;
# match preview/unfurl bot user-agents # match preview/unfurl bot user-agents
map $http_user_agent $unfurlbot { map $http_user_agent $unfurlprefix {
default 0; default "";
} }
# mempool configuration # mempool configuration

View file

@ -48,8 +48,8 @@ add_header Vary Cookie;
# for exact / requests, redirect based on $lang # for exact / requests, redirect based on $lang
# cache redirect for 5 minutes # cache redirect for 5 minutes
location = / { location = / {
if ($unfurlbot) { if ($unfurlprefix != '') {
proxy_pass $mempoolSpaceUnfurler; rewrite ^(.*)$ $unfurlprefix$1 last;
} }
if ($lang != '') { if ($lang != '') {
return 302 $scheme://$host/$lang/; return 302 $scheme://$host/$lang/;
@ -65,15 +65,15 @@ location ~ ^/([a-z][a-z])/(.+\..+\.(js|css))$ {
} }
# cache everything else for 5 minutes # cache everything else for 5 minutes
location ~ ^/([a-z][a-z])$ { location ~ ^/([a-z][a-z])$ {
if ($unfurlbot) { if ($unfurlprefix != '') {
proxy_pass $mempoolSpaceUnfurler; rewrite ^(.*)$ $unfurlprefix$1 last;
} }
try_files $uri /$1/index.html /en-US/index.html =404; try_files $uri /$1/index.html /en-US/index.html =404;
expires 5m; expires 5m;
} }
location ~ ^/([a-z][a-z])/ { location ~ ^/([a-z][a-z])/ {
if ($unfurlbot) { if ($unfurlprefix != '') {
proxy_pass $mempoolSpaceUnfurler; rewrite ^(.*)$ $unfurlprefix$1 last;
} }
try_files $uri /$1/index.html /en-US/index.html =404; try_files $uri /$1/index.html /en-US/index.html =404;
expires 5m; expires 5m;
@ -104,16 +104,53 @@ location /preview {
} }
# unfurl renderer # unfurl renderer
location ^~ /render { location ^~ /render {
proxy_pass $mempoolSpaceUnfurler; try_files /dev/null @mempool-space-unfurler;
expires 10m; 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 # catch-all for all URLs i.e. /address/foo /tx/foo /block/000
# cache 5 minutes since they change frequently # cache 5 minutes since they change frequently
location / { location / {
if ($unfurlbot) { if ($unfurlprefix != '') {
proxy_pass $mempoolSpaceUnfurler; rewrite ^(.*)$ $unfurlprefix$1 last;
} }
try_files /$lang/$uri $uri /en-US/$uri /en-US/index.html =404; try_files /$lang/$uri $uri /en-US/$uri /en-US/index.html =404;
expires 5m; 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;
}