To redirect all http requests to https:
server {
listen 80;
rewrite ^/(.*) https://$host$request_uri permanent;
}
to remove sub domain from request and redirect to domain:
server {
if ($host ~* (.*)\.(domain\.com)){
set $host_without_subdomain $2;
rewrite ^(.*)$ https://$host_without_subdomain$1 permanent;
}
}