My website uses many subdomains. What I need is to root requests to each folder depending of subdomain: src.mydomain.com to /public api.mydomain.com to /public Anyother subdomain xxx.mydomain.com to /dist I tried this settings without success: server { listen 8080; listen [::]:8080; server_name ~^(?.+)\.mydomain\.com$; set $folder "dist"; if ($subdomain = "src"){ set $folder "public"; } if ($subdomain = "api"){ set $folder "public"; } root "/home/site/wwwroot/$folder"; index index.php index.html; location / { index index.php index.html; } }