if ($scheme = http) {
return 301 https://$host$request_uri;
}

或者

if ($server_port = 80) {
    return 301 https://$server_name$request_uri;
}
if ($scheme = http) {
    return 301 https://$server_name$request_uri;
}
error_page 497 https://$server_name$request_uri;