准备:需要泛域名 domain.com。
主机:www.domain.com 或 domain.com。
思路:将*.domain.com 解析到主机www.domain.com/*/ (*不能为www或空)。
配置:
if ( $host ~* (\b(?!www\b)\w+)\.\w+\.\w+ ) {
set $subdomain $1;
}
location / {
root D:\www\domain.com\$subdomain;
index index.html index.htm;
}
测试
环境:Window7 + Nginx1.1.15<