Upstreams needs to be combination of prefix+Pool for this to work
Why ? Check the map bellow.
Map contains regular expression that gets the $host variable. strips everything after the first dot(including the dot) puts it in to a variable $h and then creates a pool that is combination of the variable $h plus the word Pool. example output would be:
reports reportsPool;
Redirect this block listens on port 80 of the servers for the domains and then redirects them to https
Listen on port 443 for domains
Proxy pass to the Map
upstream reportsPool { server 10.0.0.11:10011; #server1 server 10.0.0.12:10011; #server2 keepalive 50; } upstream monitorinPool { server 10.0.0.11:10012; #server1 server 10.0.0.12:10012; #server2 keepalive 50; } upstream cookiesPool { server 10.0.0.16:10013; #server3 server 10.0.0.15:10013; #server4 keepalive 50; } map $host $destPool { "~^(?<h>[^.]+)" "${h}Pool"; } server { listen 80; server_name reports.domain.priv monitorin.domain.priv cookies.domain.priv ; return 301 https://$http_host; } server { listen 443 ssl http2; server_name reports.domain.priv monitorin.domain.priv cookies.domain.priv ; ssl_certificate certs/domain.priv.crt; ssl_certificate_key certs/domain.priv.key; location / { proxy_connect_timeout 5; proxy_next_upstream error timeout http_500 http_502 http_503; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Connection ""; proxy_pass http://$destPool; } }