# FreeBSD configuration
user nobody;
pid /var/run/nginx.pid;

worker_processes auto;
worker_rlimit_nofile 100000;

events {
	worker_connections 9000;
	multi_accept on;
}

http {
	# DNS servers for on-demand recursive resolver
	resolver 8.8.8.8;

	# HTTP basic configuration
	include mempool/production/nginx/http-basic.conf;
	include mempool/production/nginx/http-proxy-cache.conf;
	include mempool/production/nginx/http-language.conf;

	# mempool backend configuration
	include mempool/production/nginx/upstream-mempool.conf;

	# electrs backend configuration
	include mempool/production/nginx/upstream-electrs.conf;
	include mempool/production/nginx/server-electrs.conf;

	# MEMPOOL.NINJA
	server {
		# clearnet v4/v6
		listen 443 ssl http2;
		listen [::]:443 ssl http2;
		server_name mempool.ninja;

		# for services from mempool.space like contributors on about page
		set $mempoolSpaceServices "https://mempool.space";

		# for mempool/backend daemon, see upstream-mempool.conf
		set $mempoolBackend "http://mempool-bitcoin-mainnet";

		# for blockstream/electrs daemon, see upstream-electrs.conf
		set $electrsBackend "http://electrs-bitcoin-mainnet";

		# tor v3
		listen 127.0.0.1:81;
		set $onion "mempoolhqx4isw62xs7abwphsq7ldayuidyx2v2oethdhhj6mlo2r6ad";

		# filesystem paths
		root /mempool/public_html/mainnet/;
		access_log /var/log/nginx/mempool-access.log;
		error_log /var/log/nginx/mempool-error.log;

		# ssl configuration
		ssl_certificate /usr/local/etc/letsencrypt/live/mempool.ninja/fullchain.pem;
		ssl_certificate_key /usr/local/etc/letsencrypt/live/mempool.ninja/privkey.pem;
		include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
		ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;

		# site configuration
		include mempool/production/nginx/server-mempool.conf;
	}
	# BISQ.NINJA
	server {
		# clearnet v4/v6
		listen 443 ssl http2;
		listen [::]:443 ssl http2;
		server_name bisq.ninja;

		# for services from mempool.space like contributors on about page
		set $mempoolSpaceServices "https://mempool.space";

		# for mempool/backend daemon, see upstream-mempool.conf
		set $mempoolBackend "http://mempool-bisq-mainnet";

		# for blockstream/electrs daemon, see upstream-electrs.conf
		set $electrsBackend "http://electrs-bitcoin-mainnet";

		# tor v3
		listen 127.0.0.1:82;
		set $onion "bisqmktse2cabavbr2xjq7xw3h6g5ottemo5rolfcwt6aly6tp5fdryd";

		# filesystem paths
		root /mempool/public_html/bisq/;
		access_log /var/log/nginx/bisq-access.log;
		error_log /var/log/nginx/bisq-error.log;

		# ssl configuration
		ssl_certificate /usr/local/etc/letsencrypt/live/bisq.ninja/fullchain.pem;
		ssl_certificate_key /usr/local/etc/letsencrypt/live/bisq.ninja/privkey.pem;
		include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
		ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;

		# site configuration
		include mempool/production/nginx/server-bisq.conf;
	}
	# LIQUID.PLACE
	server {
		# clearnet v4/v6
		listen 443 ssl http2;
		listen [::]:443 ssl http2;
		server_name liquid.place;

		# for services from mempool.space like contributors on about page
		set $mempoolSpaceServices "https://mempool.space";

		# for mempool/backend daemon, see upstream-mempool.conf
		set $mempoolBackend "http://mempool-liquid-mainnet";

		# for blockstream/electrs daemon, see upstream-electrs.conf
		set $electrsBackend "http://electrs-liquid-mainnet";

		# tor v3
		listen 127.0.0.1:83;
		set $onion "liquidmom47f6s3m53ebfxn47p76a6tlnxib3wp6deux7wuzotdr6cyd";

		# filesystem paths
		root /mempool/public_html/liquid/;
		access_log /var/log/nginx/liquid-access.log;
		error_log /var/log/nginx/liquid-error.log;

		# ssl configuration
		ssl_certificate /usr/local/etc/letsencrypt/live/liquid.place/fullchain.pem;
		ssl_certificate_key /usr/local/etc/letsencrypt/live/liquid.place/privkey.pem;
		include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
		ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;

		# site configuration
		include mempool/production/nginx/server-liquid.conf;
	}
	# HTTP to HTTPS redirect
	server {
		# clearnet v4/v6
		listen 80;
		listen [::]:80;
		server_name _;

		# only redirect for our hosted domains
		if ($host ~ "^(mempool.ninja|bisq.ninja|liquid.place)$")
		{
			return 301 https://$host$request_uri;
		}
		return 503;
	}
}
