# Run nginx in foreground.
daemon off;

# This is run inside Docker.
user root;

# Pid storage location.
pid /var/run/nginx.pid;

# Set number of worker processes.
worker_processes 1;

# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;

# Write error log to the add-on log.
error_log /proc/1/fd/1 error;

# Max num of simultaneous connections by a worker process.
events {
    worker_connections 512;
}

http {
	# Includes mapping of file name extensions to MIME types of responses
	# and defines the default type.
	include /etc/nginx/includes/mime.types;

    log_format homeassistant '[$time_local] $status '
                             '$http_x_forwarded_for($remote_addr) '
                             '$request ($http_user_agent)';

	access_log              /proc/1/fd/1 homeassistant;
	default_type 			application/octet-stream;

	# Name servers used to resolve names of upstream servers into addresses.
	# It's also needed when using tcpsocket and udpsocket in Lua modules.
	#resolver 208.67.222.222 208.67.220.220;

	# Don't tell nginx version to clients.
	server_tokens 			off;

	# Specifies the maximum accepted body size of a client request, as
	# indicated by the request header Content-Length. If the stated content
	# length is greater than this size, then the client receives the HTTP
	# error code 413. Set to 0 to disable.
	client_max_body_size 	1m;

	# Timeout for keep-alive connections. Server will close connections after
	# this time.
	keepalive_timeout 		65;

	# Sendfile copies data between one FD and other from within the kernel,
	# which is more efficient than read() + write().
	sendfile 				on;

	# Don't buffer data-sends (disable Nagle algorithm).
	# Good for sending frequent small bursts of data in real time.
	tcp_nodelay 			on;

	# Causes nginx to attempt to send its HTTP response head in one packet,
	# instead of using partial frames.
	#tcp_nopush 			on;

#	# Specifies that our cipher suits should be preferred over client ciphers.
#	ssl_prefer_server_ciphers on;
#
#	# Protocol and ciphers.
#	# This is what Mozilla calls "Modern configuration".
#	ssl_protocols TLSv1.2;
#	ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256';
#
#	# Enables a shared SSL cache with size that can hold around 8000 sessions.
#	ssl_session_cache shared:SSL:2m;

	# Enable checking the existence of precompressed files.
	#gzip_static on;

#	# Specifies the main log format.
#	log_format main '$remote_addr - $remote_user [$time_local] "$request" '
#			'$status $body_bytes_sent "$http_referer" '
#			'"$http_user_agent" "$http_x_forwarded_for"';

#	# Sets the path, format, and configuration for a buffered log write.
#	access_log /config/log/nginx/access.log main;

##	include /etc/nginx/includes/resolver.conf;
	
	map $http_upgrade $connection_upgrade {
	default upgrade;
	''      close;
	}

	# Includes virtual host config.
	include /etc/nginx/servers/*.conf;
}

#stream {
#	# Include optional stream to handle encrypted VNC connection.
#	include /etc/nginx/includes/default_stream.conf;
#}

