神剑山庄资源网 Design By www.hcban.com
一 虚拟主机
1.1 虚拟主机概念
对于Nginx而言,每一个虚拟主机相当于一个在同一台服务器中却相互独立的站点,从而实现一台主机对外提供多个 web 服务,每个虚拟主机之间是独立的,互不影响的。
1.2 虚拟主机类型
通过 Nginx 可以实现虚拟主机的配置,Nginx 支持三种类型的虚拟主机配置:
- 基于 IP 的虚拟主机(较少使用)
- 基于域名的虚拟主机
- 基于端口的虚拟主机
二 基于IP虚拟主机
2.1 配置多IP地址
[root@nginx ~]# ifconfig eth0:0 172.24.8.70 broadcast 172.24.8.255 netmask 255.255.255.0 [root@nginx ~]# ip addr | grep 172 inet 172.24.8.71/24 brd 172.24.8.255 scope global noprefixroute eth0 inet 172.24.8.72/24 brd 172.24.8.255 scope global secondary eth0:0
提示:如上在同一台主机添加多个IP地址。
2.2 创建站点目录
[root@nginx ~]# mkdir /usr/share/nginx/ipvhost01/ [root@nginx ~]# mkdir /usr/share/nginx/ipvhost02/ [root@nginx ~]# echo '<h1>Ipvhost01</h1>' > /usr/share/nginx/ipvhost01/index.html [root@nginx ~]# echo '<h1>Ipvhost02</h1>' > /usr/share/nginx/ipvhost02/index.html
2.3 配置虚拟主机
[root@nginx ~]# vi /etc/nginx/conf.d/ipvhost.conf server { listen ; #监听端口 server_name ipvhost.odocker.com ...; #配置虚拟主机名和IP location / { root /usr/share/nginx/ipvhost; #请求匹配路径 index index.html; #指定主页 access_log /var/log/nginx/ipvhost.access.log main; error_log /var/log/nginx/ipvhost.error.log warn; } } server { listen ; server_name ipvhost.odocker.com ...; location / { root /usr/share/nginx/ipvhost; index index.html; access_log /var/log/nginx/ipvhost.access.log main; error_log /var/log/nginx/ipvhost.error.log warn; } }
[root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 [root@nginx ~]# nginx -s reload #重载配置文件
2.4 确认验证
浏览器访问:ipvhost01.odocker.com。
clipboard
浏览器访问:ipvhost02.odocker.com。
clipboard
三 基于域名虚拟主机
3.1 创建站点目录
[root@nginx ~]# mkdir /usr/share/nginx/webvhost01/ [root@nginx ~]# mkdir /usr/share/nginx/webvhost02/ [root@nginx ~]# echo '<h1>Webvhost01</h1>' > /usr/share/nginx/webvhost01/index.html [root@nginx ~]# echo '<h1>Webvhost02</h1>' > /usr/share/nginx/webvhost02/index.html
3.2 配置虚拟主机
[root@nginx ~]# vi /etc/nginx/conf.d/webvhost.conf server { listen ; server_name webvhost.odocker.com; location / { root /usr/share/nginx/webvhost; index index.html; access_log /var/log/nginx/webvhost.access.log main; error_log /var/log/nginx/webvhost.error.log warn; } } server { listen ; server_name webvhost.odocker.com; location / { root /usr/share/nginx/webvhost; index index.html; access_log /var/log/nginx/webvhost.access.log main; error_log /var/log/nginx/webvhost.error.log warn; } }
[root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 [root@nginx ~]# nginx -s reload #重载配置文件
3.3 确认验证
浏览器访问:webvhost01.odocker.com。
clipboard
浏览器访问:webvhost02.odocker.com。
clipboard
四 基于端口虚拟主机
4.1 创建站点目录
[root@nginx ~]# mkdir /usr/share/nginx/portvhost01/ [root@nginx ~]# mkdir /usr/share/nginx/portvhost02/ [root@nginx ~]# echo '<h1>Portvhost01</h1>' > /usr/share/nginx/portvhost01/index.html [root@nginx ~]# echo '<h1>Portvhost01</h1>' > /usr/share/nginx/portvhost02/index.html
4.2 配置虚拟主机
[root@nginx ~]# vi /etc/nginx/conf.d/portvhost.conf server { listen ; server_name portvhost.odocker.com; location / { root /usr/share/nginx/portvhost; index index.html; access_log /var/log/nginx/portvhost.access.log main; error_log /var/log/nginx/portvhost.error.log warn; } } server { listen ; server_name portvhost.odocker.com; location / { root /usr/share/nginx/portvhost; index index.html; access_log /var/log/nginx/access_portvhost.log main; } }
[root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #检查配置文件 [root@nginx ~]# nginx -s reload #重载配置文件
4.3 确认验证
浏览器访问:portvhost01.odocker.com:8080
clipboard
浏览器访问:portvhost02.odocker.com:8081
clipboard
神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com
暂无深入浅析Nginx虚拟主机的评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2024年09月19日
2024年09月19日
- 【原神】V5.0攻略 |「雷电将军」一图流丨角色解析攻略
- 《原神》4.7被埋藏的荣耀任务怎么做?
- 尤雅.1995-情海茫茫【怀登唱片】【WAV+CUE】
- 张宇.1995-一言难揪EMI百代】【WAV+CUE】
- 尹毓恪.2018-浴室与太平洋【海蝶】【FLAC分轨】
- 《遗迹2:黑暗的视界》发布全新职业护卫者预告片,将于9月25日上线
- 好评如潮《彼方的她》迎来首次大型更新
- 《最终幻想16》PC版震撼登场 官方发布精彩宣传片
- 《中国十大国语老歌.男人篇 3CD》[WAV/分轨][1.5GB]
- 《汽车音响极品流行热曲发烧大碟 情伤 男声篇2CD》[WAV/分轨][980MB]
- 《绝版经典情歌 国语老歌 内地珍藏篇 2CD》[WAV/分轨][1.2GB]
- 崩坏星穹铁道冬城史学家成就获得攻略
- 金铲铲之战符文大陆城邦效果分享 有哪些效果
- 仙境传说新启航单手斧流派技能流铁匠玩法介绍
- 归龙潮笼鸟意未平任务怎么完成 笼鸟意未平任务流程攻略