网站的目录结构为:

# tree /home/wwwroot/application.pub
/home/wwwroot/application.pub
├── ai
│   └── index.html
└── file
    └── index.html

/home/wwwroot/application.pub为nginx的安装目录下默认的存放源代码的路径。
ai为博客程序源代码路径
file为附件路径
把相应程序放入上面的路径通过
http://ai.application.pub 访问博客
http://file.application.pub 访问附件
其它二级域名类推。

方法一:

server {
listen 80;
server_name ~^(?<subdomain>.+).application.pub$;
access_log /data/wwwlogs/application.pub_nginx.log combined;
index index.html index.htm index.php;
root /home/wwwroot/application.pub/$subdomain/;
...
}

方法二:

server {
listen 80;
server_name *.application.pub;
access_log /home/wwwlogs/application.pub.log combined;
index index.html index.htm index.php;

if ($host ~* ^([^\.]+)\.([^\.]+\.[^\.]+)$) {
    set $subdomain $1;
    set $domain $2;
}

location / {
    root /home/wwwroot/application.pub/$subdomain/;
    index index.php $subdomain.html index.htm;
}

...
}