利用nginx泛域名解析配置二级域名和多域名
网站的目录结构为
html
├── bbs
└── www
html为nginx的安装目录下默认的存放源代码的路径。
bbs为论坛程序源代码路径
www为主页程序源代码路径
把相应程序放入上面的路径通过
http://www.youdomain.com 访问的就是主页
http://bbs.yourdomain.com 访问的就是论坛
其它二级域名类推。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
server {
listen 80;
server_name ~^(?<subdomain>.+).yourdomain.com$;
root html/$subdomain;
index index.html index.htm index.php;
fastcgi_intercept_errors on;
error_page 404 = /404.html;
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't
# break when using query string
try_files $uri $uri/ =404;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param domain $subdomain;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /.ht {
deny all;
}
}
|
总结一下步骤就是
1.把上面的红色配置换成你的域名后添加到你的nginx.conf配置文件
2.确认要增加的二级域名,如bbs.yourdomain.com
3.设置bbs.yourdomain.com解析到你的nginx服务器ip
4.在html目录下创建bbs目录
5.把源码放入bbs目录
6.重新加载nginx配置
kill -HUP cat /usr/local/lnmp/nginx/nginx.conf
(需要把上面命令的路径换成你的配置文件路径)
7.访问http://bbs.yourdomain.com
本博客Android APP 下载 |
![]() |
支持我们就给我们点打赏 |
![]() |
支付宝打赏 支付宝扫一扫二维码 |
![]() |
微信打赏 微信扫一扫二维码 |
![]() |
如果想下次快速找到我,记得点下面的关注哦!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2016-12-12 【新书推荐】《微软开源跨平台移动开发实践》带你走近微软开源开源跨平台技术
2016-12-12 一个基于Microsoft Azure、ASP.NET Core和Docker的博客系统
2016-12-12 ASP.NET MVC中Unobtrusive Ajax的妙用
2016-12-12 CYQ.Data 数据层框架 CYQ.Data 数据框架 使用篇四 MAction 增删改