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_proto ""; if ($trust_forwarded_proto = T){ set $test_proto "${test_proto}T"; } if ($http_x_forwarded_proto = "https") { set $test_proto "${test_proto}S"; } if ($http_x_forwarded_scheme = "https") { set $test_proto "${test_proto}S"; } if ($test_proto = "TSS") { set $test_proto "TS"; } if ($test_proto = "TS") { set $test "${test}S"; } if ($test = H) { return 301 https://$host$request_uri; }