Just place the code snippet inside the server tag

#nginx default
if ($scheme != "https") {
    rewrite ^ https://$host$uri permanent;
}