首页 > 其他 > 详细

基于PORT、ip和主机头的多虚拟主机

时间:2019-05-14 00:03:30      阅读:173      评论:0      收藏:0      [点我收藏+]
实验:基于PORT的多虚拟主机

1.创建3个不同的网站文件根目录

mkdir /data/site{1,2,3}
echo ‘www.a.com‘ > /data/site1/index.html
echo ‘www.b.com‘ > /data/site2/index.html
echo ‘www.c.com‘ > /data/site3/index.html
技术分享图片![]

2.修改或在conf.d目录下创建一个.conf结尾的文件,并添加如下参数

vim /etc/httpd/conf.d/vhosts.conf

listen 8001  
listen 8002  
listen 8003  

<virtualhost *:8001>   
documentroot /data/site1  
<directory /data/site1>  
require all granted  
</directory>  
</virtualhost>  

<virtualhost *:8002>  
<directory /data/site2>                                
require all granted
</directory>  
documentroot /data/site2  
</virtualhost>  

<virtualhost *:8003>  
<directory /data/site3>                   
require all granted  
</directory>  
documentroot /data/site3  
</virtualhost>  

技术分享图片

实验:基于ip的多虚拟主机

1.给单个网卡绑定多个ip地址

ip a a 192.168.36.8/24 dev eth0
ip a a 192.168.36.9/24 dev eth0
技术分享图片

2.修改参数

vim /etc/httpd/conf.d/vhosts.conf

<virtualhost 192.168.36.7:80>  
documentroot /data/site1  
<directory /data/site1>  
require all granted  
</directory>  
</virtualhost>  

<virtualhost 192.168.36.8:80>  
<directory /data/site2>  
require all granted  
</directory>  
documentroot /data/site2  
</virtualhost>  

<virtualhost 192.168.36.9:80>                                    
<directory /data/site3>  
require all granted   
</directory>  
documentroot /data/site3  
</virtualhost>  

技术分享图片

实验:基于主机头的多虚拟主机

1.修改配置文件

vim /etc/httpd/conf.d/vhosts.conf 
<virtualhost *:80>
documentroot /data/site1
servername www.a.com
<directory /data/site1>
require all granted
</directory>
CustomLog "logs/a_access_log" combined
</virtualhost>

<virtualhost *:80>
<directory /data/site2>                                                                                               
require all granted
</directory>
documentroot /data/site2
servername www.b.com
CustomLog "logs/b_access_log" combined
</virtualhost>

<virtualhost *:80>
servername www.c.com
<directory /data/site3>                                                                                               
require all granted
</directory>
documentroot /data/site3
CustomLog "logs/c_access_log" combined
</virtualhost>

技术分享图片

2.在测试机hosts文件中添加名词解析

vim /etc/hosts
192.168.36.7 www.a.com www.b.com www.c.com
技术分享图片

基于PORT、ip和主机头的多虚拟主机

原文:https://blog.51cto.com/14234933/2393713

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!