为了降低网站构建及运行成本 ,出现了”虚拟Web主机“、在同一服务器上运行多个Web站点的应用,
其中每一个站点实际上并不独立占用整个服务器,使用虚拟Web主机可以充分利用服务器的硬件资源,大大
降低网站构建及运行成本(本实验紧凑Web服务基本搭建和访问控制)
下面来了解下虚拟Web主机的运作和DNS的结合案例:
一、新建HTTP子配置文件
[root@rh_1 ~]# cd /etc/httpd/conf.d/ [root@rh_1 conf.d]# touch 360.conf //新建子配置文件 [root@rh_1 conf.d]# cat 360.conf NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin abc@360.com DocumentRoot /var/www/html //网页文件跟目录 ServerName www.360.com //本站点的FQDN名称 ErrorLog logs/www.360.com-error_log //错误日志文件路径 CustomLog logs/www.360.com_log common //访问日志文件路径 </VirtualHost> <VirtualHost *:80> ServerAdmin abc@360.com DocumentRoot /var/www/sina ServerName sina.360.com ErrorLog logs/sina.360.com-error_log CustomLog logs/sina.360.com_log common </VirtualHost> <VirtualHost *:80> ServerAdmin abc@360.com DocumentRoot /var/www/baidu ServerName baidu.360.com ErrorLog logs/baidu.360.com-error_log CustomLog logs/baidu.360.com_log common </VirtualHost>
二、部署网站相应文件和网页文档
[root@rh_1 conf.d]# mkdir /var/www/baidu [root@rh_1 conf.d]# mkdir /var/www/sina [root@rh_1 conf.d]# touch /var/www/sina/index.html [root@rh_1 conf.d]# touch /var/www/baidu/index.html [root@rh_1 conf.d]# cat /var/www/sina/index.html sina.360.com [root@rh_1 conf.d]# cat /var/www/baidu/index.html baidu.360.com [root@rh_1 conf.d]# service httpd restart
三、修改DNS本地区域数据文件
[root@DNS ~]# cd /var/named/chroot/var/named/ [root@DNS named]# vim 360.zone [root@DNS named]# cat 360.zone $TTL86400 @ IN SOA 360.com. root.360.com. ( 1997022700 ; Serial 28800 ; Refresh 14400 ; Retry 3600000 ; Expire 86400 ) ; Minimum IN NS dns1.360.com. dns1 IN A 192.168.122.20 www IN A 192.168.122.10 baidu IN A 192.168.122.10 sina IN A 192.168.122.10 * IN A 192.168.122.10 //泛域名解析,当输入 以“360.com”结尾的网址,会访文wwww.360.com
[root@DNS named]# service named restart
在客户端访问:
www.360.com. baidu.360.com. sina.360.com. sin.360.com
本文出自 “linux网络服务搭建” 博客,请务必保留此出处http://8824130.blog.51cto.com/8814130/1405578