How to configure nginx to configure domain names for each subdirectory in a virtual host?
The requirement is that two directories, home and admin
, are placed in a virtual host.
Home binding home.xx.com
admin binds admin.xx.com
I don’t want to create two virtual hosts.
phpcn_u15822017-05-16 17:30:28
server {
listen 80;
server_name *.xx.com;
# set a default root
set $rootdir /home/xx/public_html;
# try if is a subdomain
if ($host ~* ^(.+)\.xx\.com$) {
set $rootdir /home/xx/subdomains/$1;
}
root $rootdir;
}