首页 > 代码库 > httpd基于域名的虚拟主机
httpd基于域名的虚拟主机
搭建基于域名的网站虚拟主机。
web虚拟主机服务器 | centos6.5 | 192.168.200.202 | 搭建基于域名的虚拟主机 |
dns、ftp服务器 | centos6.5 | 192.168.200.254 | 提供DNS解析,ftp下载 |
1:在dns服务器上设置dns解析:
修改dns的配置文件,设置区域文件名称和所在位置。
[root@localhost ~]# cd /var/named/chroot/etc/ [root@localhost etc]# vi named.conf [root@localhost ~]# cat /var/named/chroot/etc/named.conf options { listen-on port 53{ any; }; forwarders { 202.106.0.20;114.114.114.114;8.8.8.8; }; directory "/var/named"; }; zone "leslie.cn." IN { type master; file "leslie.cn.zone"; }; zone "leslie.com." IN { type master; file "leslie.com.zone"; };
配置区域文件,添加记录。两个虚拟主机要建两个区域文件,
分别是www.leslie.com.zone和www.leslie.cn.zone
[root@localhost etc]# cd ../var/named/ [root@localhost named]# vi leslie.cn.zone [root@localhost ~]# cat /var/named/chroot/var/named/leslie.cn.zone $TTL 86400 @INSOAleslie.cn.root.leslie.cn. ( 20150630 1H 2M 3W 1D ) @INNSns.leslie.cn. mailINMX 10mail.leslie.cn. @INA192.168.200.254 mailINA192.168.200.254 nsINA192.168.200.254 ftpINA192.168.200.254 ntpINCNAMEns wwwINA192.168.200.202
[root@localhost named]# vi leslie.com.zone [root@localhost ~]# cat /var/named/chroot/var/named/leslie.com.zone $TTL 86400 @INSOAleslie.com.root.leslie.com. ( 20150630 1H 2M 3W 1D ) @INNSns.leslie.com. mailINMX 10mail.leslie.com. @INA192.168.200.254 mailINA192.168.200.254 nsINA192.168.200.254 ftpINA192.168.200.254 ntpINCNAMEns wwwINA192.168.200.202
设置完成后重启named服务:
[root@localhost named]# /etc/init.d/named restart 停止 named:. [确定] 启动 named: [确定]
解析测试:
[root@localhost named]# nslookup > server 192.168.200.254 Default server: 192.168.200.254 Address: 192.168.200.254#53 > www.leslie.com Server:192.168.200.254 Address:192.168.200.254#53 Name:www.leslie.com Address: 192.168.200.202 > www.leslie.cn Server:192.168.200.254 Address:192.168.200.254#53
安装httpd服务:
使用yum安装:
[root@localhost ~]# yum -y install httpd &>>/dev/null ##红色部分是不看输出内容,不显示信息
编辑配置文件/etc/httpd/conf/httpd.conf
277 ServerName www.leslie.com:80 990 NameVirtualHost 192.168.200.202:80 991 <VirtualHost 192.168.200.202:80> 992 ServerAdmin admin@leslie.com 993 DocumentRoot "/var/www/html/www.leslie.com" 994 ServerName www.leslie.com 995 ErrorLog logs/www.leslie.com.com-error_log 996 CustomLog logs/www.leslie.com.com-access_log common 997 </VirtualHost> 998 <VirtualHost 192.168.200.202:80> 999 ServerAdmin admin@leslie.cn 1000 DocumentRoot "/var/www/html/www.leslie.cn" 1001 ServerName www.leslie.cn 1002 ErrorLog logs/www.leslie.cn-error_log 1003 CustomLog logs/www.leslie.cn-access_log common 1004 </VirtualHost>
新建网页根目录 和配置文件中DocumentRoot 中的一样:
[root@localhost conf]# cd /var/www/html/ [root@localhost html]# mkdir www.leslie.com [root@localhost html]# mkdir www.leslie.cn [root@localhost html]# echo "www.leslie.com" >>www.leslie.com/index.html [root@localhost html]# echo "www.leslie.cn" >>www.leslie.cn/index.html [root@localhost html]# cat www.leslie.com/index.html www.leslie.com [root@localhost html]# cat www.leslie.cn/index.html www.leslie.cn
重启httpd服务
[root@localhost ~]# /etc/init.d/httpd restart 停止 httpd: [确定] 正在启动 httpd: [确定]
检测服务:
[root@localhost ~]# netstat -utpln |grep httpd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 53492/httpd
测试:
[root@localhost ~]# elinks --dump www.leslie.com www.leslie.com [root@localhost ~]# elinks --dump www.leslie.cn www.leslie.cn
本文出自 “向往技术的小白” 博客,请务必保留此出处http://lesliecheung.blog.51cto.com/12622169/1956240
httpd基于域名的虚拟主机
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。