Nginx泛解析的匹配域名綁定到子目錄配置


網站的目錄結構為:

# tree /home/wwwroot/lvtao.net
/home/wwwroot/lvtao.net
├── blog
│   └── index.html
└── file
    └── index.html

/home/wwwroot/lvtao.net為nginx的安裝目錄下默認的存放源代碼的路徑。
blog為博客程序源代碼路徑
file為附件路徑
把相應程序放入上面的路徑通過
http://blog.lvtao.net 訪問博客
http://file.lvtao.net 訪問附件
其它二級域名類推。

方法一:

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;
}

...
}
``


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM