It's possible.
#put this in the http context
proxy_http_version 1.1; #default is HTTP/1.0
-
#example server blocks
#redirect to https
server {
listen 80;
server_name "~^(.+\.)?example\d{2}\.com$"; #regex to match example[number].com and *.example[number].com
return 301 https://$host$request_uri;
}
#https
#example01.com
server {
listen 443 ssl http2;
server_name example01.com;
proxy_pass http://10.0.2.2;
#your config;
}
#foo.example01.com
server {
listen 443 ssl http2;
server_name foo.example01.com;
proxy_pass http://10.0.2.2:12000;
#your config;
}
#example02.com
server {
listen 443 ssl http2;
server_name example02.com;
proxy_pass https://10.0.3.2;
#your config;
}