server { listen 80; server_name ~^(?\w*)\.${DOMAIN}.${ZONE}${DOLLAR}; location / { if ($http_x_subdomain = "") { set $http_x_subdomain $subdomain; } proxy_set_header X-Subdomain $http_x_subdomain; proxy_pass http://${SERVER}:${SERVER_PORT}/; } } server { listen 80; server_name ${DOMAIN}.${ZONE}; location / { proxy_pass http://${SERVER}:${SERVER_PORT}/; } }