访问Apache虚拟主机的方式(理论部分)

构建虚拟主机

■虚拟Web主机
●在同一台服务器中运行多个Web站点,其中每一一个站点并不独立
占用一台真正的计算机
■httpd支持的虚拟主机类型
●基于域名的虚拟主机
●基于IP地址的虚拟主机
●基于端口的虚拟主机:

构建虚拟主机一 基于域名

■应用示例:

●构建2个虚拟Web站点
www.kgc.com, IP地址为173.17.17.11
www.kcce.com, IP地址为173.17.17.11
●在浏览器中访问这两个域名时,分别显示不同的内容

1.为虚拟主机提供域名解析

[[email protected] ~]# vim /var/named/chroot/var/named/kgc.com.zone
@ IN NS dnssvr.kgc.com.
dnssvr IN A 173.1 7.1 7.2
www IN A 173.17.17.11
[[email protected] ~]# vim /var/named/chroot/var/named/kcce.com.zone
......
@ IN NS dnssvr.kgc.com.
www IN A 173.17.1711

2.为虚拟主机准备网页文档

[[email protected] ~]# mkdir -p /var/www/html/kgc
[[email protected] ~]# mkdir -p /var/www/html/accp
[[email protected] ~]# echo " <h1>www.kgc.com</h1>" >
/var/www/html/kgccom/index.html
[[email protected] ~]# echo
! <h1>www.accp.com</h1>" >
/var/www/html/kccecom/index.html

3.添加虚拟主机配置

[[email protected] ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.comf
<VirtualHost :80>
DocumentRoot "/var/www/html/kgccom"
ServerName www.kgc.com
ErrorLog "logs/www.kgc.com.error_log"
CustomLog "logs/www.kgc.com.access_log" common
< Directory "/var/www/html" >
Require all granted
</Directory>
</VirtualHost>
<VirtualHost
:80>
DocumentRoot "/var/www/html、accp
ServerName www.accp.com
ErrorLog "logs/www.accp.com.error_log"
CustomLog "logs/www.accp.com.access_log" common
< Directory "/var/www/html" >
Require all granted
</Directory>
< /VirtualHost>

4.在客户机分别访问虚拟Web主机

构建虚拟主机——基于端口

■应用示例:

●构建2个虚拟Web站点

www.kgc.com, IP地址、 端口为173.17.17.11:80
www.accp.com, IP地址、 端口为173.17.17.11:8353
在浏览器中访问这两个端口时,分别显示不同的内容
[[email protected] ~]# vim /usr/loca/httpd/conf/extra/httpd-vhosts.conf
< VirtualHost 173.17.17.11:80习
DocumentRoot "/var/wwwhtml/kccecom"
ServerName www.kgc.com
</VirtualHost>
<VirtualHost 173.17.17.11:8353)
DocumentRoot "/var/www/html/kccepad"
ServerName www.accp.com
< NirtualHost>
Listen 80
Listen 8353

构建虚拟主机一 基于IP

■应用示例:
●构建2个虚拟Web站点
www.kgc.com, IP地址为220.181.120.61
www.kcce.com, IP地址为122.115.32.133
在浏览器中访问这两个IP时P分别显示不同的内容
[[email protected] ~]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf< VirtualHost 220.181.120.61:80>DocumentRoot "/var/www/html/kgccom"ServerName www.kgc.com</NirtualHost> I<VirtualHost 122.115.32.133:80>DocumentRoot "/var/www/htm/kccecom"ServerName www.kcce.com</VirtualHost>

相关文章
相关标签/搜索