前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Nginx二级域名自动解析&伪静态&默认首页

Nginx二级域名自动解析&伪静态&默认首页

作者头像
Laikee
发布2022-04-25 18:17:25
1.8K0
发布2022-04-25 18:17:25
举报
文章被收录于专栏:Laikee Tech SpaceLaikee Tech Space

网站的目录结构为:

代码语言:javascript
复制
# 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 访问附件 其它二级域名类推。

方法一:

代码语言:javascript
复制
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/;
...
}

方法二:

代码语言:javascript
复制
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;
}

...
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-10-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档