set $test "";
if ($scheme = "http") {
	set $test "H";
}
if ($request_uri = /.well-known/acme-challenge/test-challenge) {
	set $test "${test}T";
}

# Check if the ssl staff has been handled
set $test_ssl_handled "";
if ($trust_forwarded_proto = "") {
	set $trust_forwarded_proto "F";
}
if ($trust_forwarded_proto = "T") {
	set $test_ssl_handled "${test_ssl_handled}T";
}
if ($http_x_forwarded_proto = "https") {
	set $test_ssl_handled "${test_ssl_handled}S";
}
if ($http_x_forwarded_scheme = "https") {
	set $test_ssl_handled "${test_ssl_handled}S";
}
if ($test_ssl_handled = "TSS") {
	set $test_ssl_handled "TS";
}
if ($test_ssl_handled = "TS") {
	set $test "${test}S";
}

if ($test = H) {
	return 301 https://$host$request_uri;
}
