Nginx泛解析的匹配域名绑定到子目录配置 |
网站的目录结构为: # tree /home/wwwroot/lvtao.net /home/wwwroot/lvtao.net ├── blog │ └── index.html └── file └── index.html /home/wwwroot/lvtao.net为nginx的安装目录下默认的存放源代码的路径。 方法一: server { listen 80; server_name ~^(?<subdomain>.+).lvtao.net$; access_log /data/wwwlogs/lvtao.net_nginx.log combined; index index.html index.htm index.php; root /home/wwwroot/lvtao.net/$subdomain/; ... } 方法二: server { listen 80; server_name *.lvtao.net; access_log /home/wwwlogs/lvtao.net.log combined; index index.html index.htm index.php; if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) { set $subdomain $1; set $domain $2; } location / { root /home/wwwroot/lvtao.net/$subdomain/; index index.php index.html index.htm; } ... } `` |