0

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 ~^(?<subdomain>.+)\.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;
    }

}
CC BY-SA 4.0

1 Answer 1

2

Try this:

map $http_host $webroot {
    src.mydomain.com  /home/site/wwwroot/public;
    api.mydomain.com  /home/site/wwwroot/public;
    default           /home/site/wwwroot/dist;
}
server {
    server_name *.mydomain.com;
    root $webroot;
    ...
}
CC BY-SA 4.0
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.