<VirtualHost *:80>
	ServerAdmin webmaster@minmaxiste.com
	ServerName <%= @name %>
	ServerAlias <%= @name %> <%= @aliases.join(' ') %>

	DocumentRoot <%= @docroot %>
	RedirectMatch permanent "^(?!/.well-known/acme-challenge/.*)" https://<%= @name %>/$1

	ErrorLog ${APACHE_LOG_DIR}/<%= @name %>/error.log
	CustomLog ${APACHE_LOG_DIR}/<%= @name %>/access.log combined
</VirtualHost>

<VirtualHost *:442>
	ServerAdmin webmaster@minmaxiste.com
	ServerName <%= @name %>
	ServerAlias <%= @name %> <%= @aliases.join(' ') %>

	DocumentRoot <%= @docroot %>
	DirectoryIndex index.md index.html

	AddDefaultCharset UTF-8
	AddCharset UTF-8 .md

	ErrorLog ${APACHE_LOG_DIR}/<%= @name %>/error.log
	CustomLog ${APACHE_LOG_DIR}/<%= @name %>/access.log combined

	RemoteIPProxyProtocol On

	# Backup volumes are large and the client can be quite slow
	# preparing each, so give plenty of time in-between
	KeepAliveTimeout 600
	Timeout 600

	SSLEngine on
	SSLCertificateFile      /etc/ssl/certs/certes.pem
	SSLCertificateKeyFile   /etc/ssl/private/certes.key
	SSLCACertificateFile    /etc/certes/root.pem
	SSLVerifyClient         require
	SSLVerifyDepth          2
	SSLUserName             SSL_CLIENT_S_DN_CN

	<Directory <%= @docroot %>>
		Options <%= @docroot_options.join(' ') %>
		Order allow,deny
		Deny from all
		AllowOverride None
	</Directory>

	<Location />
		Options Indexes FollowSymlinks
		Require valid-user
		Dav On
		AllowOverride None
		RewriteEngine on
		RewriteCond expr "! %{REQUEST_URI} -strmatch '/%{REMOTE_USER}'"
		RewriteCond expr "! %{REQUEST_URI} -strmatch '/%{REMOTE_USER}/*'"
		RewriteRule ".*" "-" [F,END]
		ProxyPass "http://localhost:8081/"
	</Location>
</VirtualHost>
