网站的目录结构为:# tree /home/wwwroot/2kb.com
/home/wwwroot/2kb.com
├── blog
│ └── index.html
└── file
└── index.html复制代码
/home/wwwroot/2kb.com为nginx的安装目录下默认的存放源代码的路径。
blog为博客程序源代码路径
file为附件路径
把相应程序放入上面的路径通过
http://www.2kb.com 访问博客
http://tools.2kb.com 访问附件
其它二级域名类推。方法一:server {
listen 80;
server_name ~^(?.+).2kb.com$;
access_log /data/wwwlogs/2kb.com_nginx.log combined;
index index.html index.htm index.php;
root /home/wwwroot/2kb.com/$subdomain/;
…
}
方法二:server {
listen 80;
server_name *.2kb.com;
access_log /home/wwwlogs/2kb.com.log combined;
index index.html index.htm index.php;
if (KaTeX parse error: Got function '\.' with no arguments as superscript at position 12: host ~* ^([^̲\.]+)\.([^\.]+\…) {
set $subdomain $1;
set $domain $2;
}
location / {
root /home/wwwroot/2kb.com/$subdomain/;
index index.php index.html index.htm;
}