| 
									
										
										
										
											2022-01-04 15:28:17 +09:00
										 |  |  | # angular builds to index.html | 
					
						
							|  |  |  | index index.html; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # tor onion redirect | 
					
						
							|  |  |  | add_header Onion-Location http://$onion.onion$request_uri; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # HSTS preload enable | 
					
						
							|  |  |  | add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # generate frame configuration from origin header | 
					
						
							|  |  |  | set $frameOptions "DENY"; | 
					
						
							|  |  |  | set $contentSecurityPolicy "frame-ancestors 'none'"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # used for iframes on https://mempool.space/network | 
					
						
							|  |  |  | if ($http_referer ~ ^https://mempool.space/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	set $frameOptions "ALLOW-FROM https://mempool.space"; | 
					
						
							|  |  |  | 	set $contentSecurityPolicy "frame-ancestors https://mempool.space"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | # used for iframes on https://mempool.ninja/network | 
					
						
							|  |  |  | if ($http_referer ~ ^https://mempool.ninja/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	set $frameOptions "ALLOW-FROM https://mempool.ninja"; | 
					
						
							|  |  |  | 	set $contentSecurityPolicy "frame-ancestors https://mempool.ninja"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | # used for iframes on https://wiz.biz/bitcoin/nodes | 
					
						
							|  |  |  | if ($http_referer ~ ^https://wiz.biz/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	set $frameOptions "ALLOW-FROM https://wiz.biz"; | 
					
						
							|  |  |  | 	set $contentSecurityPolicy "frame-ancestors https://wiz.biz"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # restrict usage of frames | 
					
						
							|  |  |  | add_header X-Frame-Options $frameOptions; | 
					
						
							|  |  |  | add_header Content-Security-Policy $contentSecurityPolicy; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # enable browser and proxy caching | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | add_header Pragma "public"; | 
					
						
							|  |  |  | add_header Cache-Control "public"; | 
					
						
							| 
									
										
										
										
											2022-01-04 15:28:17 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | # vary cache if user changes language preference | 
					
						
							|  |  |  | add_header Vary Accept-Language; | 
					
						
							|  |  |  | add_header Vary Cookie; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | # see order of nginx location rules | 
					
						
							|  |  |  | # https://stackoverflow.com/questions/5238377/nginx-location-priority | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # for exact / requests, redirect based on $lang | 
					
						
							| 
									
										
										
										
											2022-07-18 17:47:33 -05:00
										 |  |  | # cache redirect for 5 minutes | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | location = / { | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	if ($unfurlprefix != '') { | 
					
						
							|  |  |  | 		rewrite ^(.*)$ $unfurlprefix$1 last; | 
					
						
							| 
									
										
										
										
											2022-08-30 16:50:31 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	if ($lang != '') { | 
					
						
							| 
									
										
										
										
											2022-07-11 15:25:42 +02:00
										 |  |  | 		return 302 $scheme://$host/$lang/; | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	try_files /en-US/index.html =404; | 
					
						
							| 
									
										
										
										
											2022-07-18 17:47:33 -05:00
										 |  |  | 	expires 5m; | 
					
						
							| 
									
										
										
										
											2022-01-04 15:28:17 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | # cache /<lang>/main.f40e91d908a068a2.js forever since they never change | 
					
						
							| 
									
										
										
										
											2023-05-25 16:50:56 +02:00
										 |  |  | location ~ ^/([a-z][a-z])/(.+\..+\.(js|css))$ { | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | 	try_files $uri =404; | 
					
						
							|  |  |  | 	expires 1y; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-07-18 17:47:33 -05:00
										 |  |  | # cache everything else for 5 minutes | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | location ~ ^/([a-z][a-z])$ { | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	if ($unfurlprefix != '') { | 
					
						
							|  |  |  | 		rewrite ^(.*)$ $unfurlprefix$1 last; | 
					
						
							| 
									
										
										
										
											2023-03-08 16:14:43 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	try_files $uri /$1/index.html /en-US/index.html =404; | 
					
						
							| 
									
										
										
										
											2022-08-27 13:54:07 +02:00
										 |  |  | 	expires 5m; | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | } | 
					
						
							|  |  |  | location ~ ^/([a-z][a-z])/ { | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	if ($unfurlprefix != '') { | 
					
						
							|  |  |  | 		rewrite ^(.*)$ $unfurlprefix$1 last; | 
					
						
							| 
									
										
										
										
											2022-08-27 13:54:07 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	try_files $uri /$1/index.html /en-US/index.html =404; | 
					
						
							| 
									
										
										
										
											2022-08-27 13:54:07 +02:00
										 |  |  | 	expires 5m; | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | # cache /resources/** for 1 week since they don't change often | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | location /resources { | 
					
						
							| 
									
										
										
										
											2022-07-11 20:18:10 +02:00
										 |  |  | 	try_files $uri /en-US/index.html; | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	expires 1w; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-10-15 19:44:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # only cache /resources/config.* for 5 minutes since it changes often | 
					
						
							|  |  |  | location /resources/config. { | 
					
						
							|  |  |  | 	try_files $uri =404; | 
					
						
							|  |  |  | 	expires 5m; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2024-05-13 16:57:14 +00:00
										 |  |  | # only cache /resources/customize.* for 5 minutes since it changes often | 
					
						
							|  |  |  | location /resources/customize. { | 
					
						
							|  |  |  | 	try_files $uri =404; | 
					
						
							|  |  |  | 	expires 5m; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-10-15 19:44:34 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | # cache /main.f40e91d908a068a2.js forever since they never change | 
					
						
							| 
									
										
										
										
											2023-05-25 16:50:56 +02:00
										 |  |  | location ~* ^/.+\..+\.(js|css)$ { | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | 	try_files /$lang/$uri /en-US/$uri =404; | 
					
						
							|  |  |  | 	expires 1y; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-08-27 14:17:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-23 01:09:11 +09:00
										 |  |  | # old stuff is gone | 
					
						
							|  |  |  | location /explorer/ { | 
					
						
							|  |  |  | 	return 410; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | location /sitemap/ { | 
					
						
							|  |  |  | 	return 410; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-27 14:17:17 +02:00
										 |  |  | # unfurl preview | 
					
						
							|  |  |  | location /preview { | 
					
						
							|  |  |  | 	try_files /$lang/$uri $uri /en-US/$uri /en-US/index.html =404; | 
					
						
							|  |  |  | 	expires 10m; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | # unfurl renderer | 
					
						
							|  |  |  | location ^~ /render { | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	try_files /dev/null @mempool-space-unfurler; | 
					
						
							| 
									
										
										
										
											2022-08-27 14:17:17 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | # unfurl handler | 
					
						
							|  |  |  | location /unfurl/ { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-space-unfurler; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | location /slurp/ { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-space-slurper; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2022-08-27 14:17:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-14 22:22:57 +09:00
										 |  |  | # catch-all for all URLs i.e. /address/foo /tx/foo /block/000 | 
					
						
							| 
									
										
										
										
											2022-07-18 17:47:33 -05:00
										 |  |  | # cache 5 minutes since they change frequently | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | location / { | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	if ($unfurlprefix != '') { | 
					
						
							|  |  |  | 		rewrite ^(.*)$ $unfurlprefix$1 last; | 
					
						
							| 
									
										
										
										
											2022-08-27 13:54:07 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-01-12 23:12:49 +09:00
										 |  |  | 	try_files /$lang/$uri $uri /en-US/$uri /en-US/index.html =404; | 
					
						
							| 
									
										
										
										
											2022-07-18 17:47:33 -05:00
										 |  |  | 	expires 5m; | 
					
						
							| 
									
										
										
										
											2022-01-04 17:27:37 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2023-08-20 02:36:34 +09:00
										 |  |  | 	proxy_cache_valid 200 1h; # will re-render page if older than this | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							| 
									
										
										
										
											2023-08-20 00:01:22 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	expires 1d; | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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; | 
					
						
							| 
									
										
										
										
											2023-08-20 02:36:34 +09:00
										 |  |  | 	proxy_cache_valid 200 1h; # will re-render page if older than this | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							| 
									
										
										
										
											2023-08-20 00:01:22 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	expires 10d; | 
					
						
							| 
									
										
										
										
											2023-08-16 03:27:09 +09:00
										 |  |  | } |