user www-data;
worker_processes {{ .Env.NGINX_WORKER_PROCESSES | default "4" }};
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections {{ .Env.NGINX_WORKER_CONNECTIONS | default "768" }};
	# multi_accept on;
}

http {

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout {{ .Env.NGINX_KEEPALIVE_TIMEOUT | default "65" }};
	types_hash_max_size 2048;
	server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	client_max_body_size 0;

	{{ if .Env.NGINX_RESOLVER }}
	resolver {{ .Env.NGINX_RESOLVER }};
	{{ end -}}

 	include /etc/nginx/mime.types;
	types {
		# add support for the wav MIME type that is requried to playback wav files in Firefox.
		audio/wav wav;
	}
	default_type application/octet-stream;

	##
	# Logging Settings
	##
	# Matches any URI or Referer with some matches and redacts the whole
	# query string. log_format and map must be at the http context level.
	map $request_uri $loggable_uri {
		~^(?P<path>[^?]*)\?.*(?:jwt|token)= "${path}?[params_redacted]";
		default $request_uri;
	}

	map $http_referer $loggable_referer {
		~^(?P<url>[^?]*)\?.*(?:jwt|token)= "${url}?[params_redacted]";
		default $http_referer;
	}

	log_format jitsi_log '$remote_addr - $remote_user [$time_local] '
		'"$request_method $loggable_uri $server_protocol" '
		'$status $body_bytes_sent "$loggable_referer" "$http_user_agent"';

	access_log /dev/stdout jitsi_log;
	error_log /dev/stderr;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_types text/plain text/css application/javascript application/json;
	gzip_vary on;
	gzip_min_length 860;

	##
	# Connection header for WebSocket reverse proxy
	##
	map $http_upgrade $connection_upgrade {
		default upgrade;
		'' close;
	}

	##
	# Virtual Host Configs
	##
	include /config/nginx/site-confs/*;
}


daemon off;
