There are many sites on the same domain. At the moment, everything is written in pens - each site is in its config. Is it possible to automatically substitute a subdomain based on existing folders in /var/www/html/sitename . If possible, are there any examples or instructions, I can not find anywhere

    1 answer 1

    For the case of sub1.site.ru => /var/www/html/sub1.site.ru

     server { listen 80; server_name *.site.ru; root /var/www/html/$host; } 

    For the case of sub1.site.ru => /var/www/html/sub1

     server { listen 80; server_name *.site.ru; root /var/www/html/$subdomain; set $subdomain ""; if ($host ~* ^([a-z0-9-]+)\.site\.ru$) { set $subdomain $1; } } 

    For arbitrary bundle sub1.site.ru => /var/www/html/sub1-dir using the map :

     map $host $sub_root_dir { sub1.site.ru sub1-dir; sub2.site.ru sub2-dir; } server { listen 80; server_name *.site.ru; root /var/www/html/$sub_root_dir; }