# Check if the original scheme is HTTP if ($scheme = "http") { return 301 https://$host$request_uri; } # Check if the request was forwarded with HTTP protocol # This is necessary when behind a proxy like Cloudflare if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; }