user www-data;
worker_processes auto;
pid /run/nginx.pid;
error_log /var/log/nginx/error.log;

events {
	worker_connections 768;
	# multi_accept on;
}

http {
	sendfile on;
	tcp_nopush on;

	# Do not emit nginx version on error pages.
	server_tokens off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
	ssl_prefer_server_ciphers on;
	ssl_certificate /var/lib/acme/live/{{ config.domain_name }}/fullchain;
	ssl_certificate_key /var/lib/acme/live/{{ config.domain_name }}/privkey;

	gzip on;

	server {
		listen 443 ssl default_server;
		listen [::]:443 ssl default_server;

		root /var/www/html;

		index index.html index.htm;

		server_name _;

		location / {
			# First attempt to serve request as file, then
			# as directory, then fall back to displaying a 404.
			try_files $uri $uri/ =404;
		}

		location /metrics {
			default_type text/plain;
		}

		# add cgi-bin support
		include /usr/share/doc/fcgiwrap/examples/nginx.conf;
	}

	# Redirect www. to non-www
	server {
		listen 443 ssl;
		listen [::]:443 ssl;
		server_name www.{{ config.domain_name }};
		return 301 $scheme://{{ config.domain_name }}$request_uri;
	}
}
