| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | ########### | 
					
						
							|  |  |  | # routing # | 
					
						
							|  |  |  | ########### | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-24 13:31:56 -05:00
										 |  |  | location /api/v1/accelerations { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-short; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | location /api/v1/assets { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-short; | 
					
						
							| 
									
										
										
										
											2023-11-18 12:19:48 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | location /api/v1/contributors { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-medium; | 
					
						
							| 
									
										
										
										
											2023-08-31 02:36:22 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | location /api/v1/contributors/images { | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-long; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | location /api/v1/donations { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-medium; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							|  |  |  | location /api/v1/donations/images { | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-long; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | location /api/v1/translators { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-medium; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							|  |  |  | location /api/v1/translators/images { | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-long; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | location /api/v1/services/internal/ { | 
					
						
							|  |  |  | 	return 403; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | location /api/v1/services/ { | 
					
						
							|  |  |  | 	try_files /dev/null @mempool-api-v1-services-cache-disabled; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ########### | 
					
						
							|  |  |  | # caching # | 
					
						
							|  |  |  | ########### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | location @mempool-api-v1-services-cache-disabled { | 
					
						
							|  |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'no-cache'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 20:20:15 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 	proxy_buffering off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expires -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | location @mempool-api-v1-services-cache-disabled-addcors { | 
					
						
							|  |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'no-cache'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 19:56:17 +09:00
										 |  |  | 	# generate CORS configuration from origin header | 
					
						
							|  |  |  | 	set $cors_methods 'GET, POST, PUT, DELETE, OPTIONS'; | 
					
						
							|  |  |  | 	set $cors_origin 'https://mempool.space'; | 
					
						
							|  |  |  | 	set $cors_headers 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With'; | 
					
						
							|  |  |  | 	set $cors_credentials 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# set CORS for approved hostnames | 
					
						
							|  |  |  | 	if ($cors_approved_origin = 'legit') | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		set $cors_methods 'GET, POST, PUT, DELETE, OPTIONS'; | 
					
						
							|  |  |  | 		set $cors_origin "$http_origin"; | 
					
						
							|  |  |  | 		set $cors_headers 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With'; | 
					
						
							|  |  |  | 		set $cors_credentials 'true'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# set CORS for approved hostnames | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Methods "$cors_methods" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Origin "$cors_origin" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Headers "$cors_headers" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Credentials "$cors_credentials" always; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 	proxy_buffering off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	expires -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | location @mempool-api-v1-services-cache-short { | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 	proxy_cache services; | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'public'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'public'; | 
					
						
							|  |  |  | 	expires 2s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# server-side cache validity | 
					
						
							|  |  |  | 	proxy_cache_valid 200 2s; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-13 20:20:15 +09:00
										 |  |  | location @mempool-api-v1-services-cache-short-addcors { | 
					
						
							|  |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 	proxy_cache services; | 
					
						
							|  |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# generate CORS configuration from origin header | 
					
						
							|  |  |  | 	set $cors_methods 'GET, POST, PUT, DELETE, OPTIONS'; | 
					
						
							|  |  |  | 	set $cors_origin 'https://mempool.space'; | 
					
						
							|  |  |  | 	set $cors_headers 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With'; | 
					
						
							|  |  |  | 	set $cors_credentials 'true'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# set CORS for approved hostnames | 
					
						
							|  |  |  | 	if ($cors_approved_origin = 'legit') | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		set $cors_methods 'GET, POST, PUT, DELETE, OPTIONS'; | 
					
						
							|  |  |  | 		set $cors_origin "$http_origin"; | 
					
						
							|  |  |  | 		set $cors_headers 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With'; | 
					
						
							|  |  |  | 		set $cors_credentials 'true'; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# set CORS for approved hostnames | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Methods "$cors_methods" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Origin "$cors_origin" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Headers "$cors_headers" always; | 
					
						
							|  |  |  | 	add_header Access-Control-Allow-Credentials "$cors_credentials" always; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'public'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'public'; | 
					
						
							|  |  |  | 	expires 2s; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# server-side cache validity | 
					
						
							|  |  |  | 	proxy_cache_valid 200 2s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | location @mempool-api-v1-services-cache-medium { | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 	proxy_cache services; | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'public'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'public'; | 
					
						
							|  |  |  | 	expires 7d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# server-side cache validity | 
					
						
							|  |  |  | 	proxy_cache_valid 200 7d; | 
					
						
							| 
									
										
										
										
											2022-01-14 20:38:10 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | location @mempool-api-v1-services-cache-long { | 
					
						
							| 
									
										
										
										
											2022-02-06 15:46:24 +00:00
										 |  |  | 	proxy_pass $mempoolSpaceServices; | 
					
						
							|  |  |  | 	proxy_cache services; | 
					
						
							| 
									
										
										
										
											2023-11-18 15:09:02 +09:00
										 |  |  | 	proxy_redirect off; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove these just in case double proxied | 
					
						
							|  |  |  | 	proxy_hide_header Onion-Location; | 
					
						
							|  |  |  | 	proxy_hide_header Strict-Transport-Security; | 
					
						
							|  |  |  | 	proxy_hide_header Content-Security-Policy; | 
					
						
							|  |  |  | 	proxy_hide_header X-Frame-Options; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# pass these headers to services backend | 
					
						
							|  |  |  | 	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; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# remove cache headers from services backend | 
					
						
							|  |  |  | 	proxy_hide_header Cache-Control; | 
					
						
							|  |  |  | 	proxy_hide_header Expires; | 
					
						
							|  |  |  | 	proxy_hide_header Pragma; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# add our own cache headers | 
					
						
							|  |  |  | 	add_header 'Pragma' 'public'; | 
					
						
							|  |  |  | 	add_header 'Cache-Control' 'public'; | 
					
						
							|  |  |  | 	expires 30d; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	# server-side cache validity | 
					
						
							|  |  |  | 	proxy_cache_valid 200 30d; | 
					
						
							| 
									
										
										
										
											2022-02-06 15:46:24 +00:00
										 |  |  | } |