##############################构建Web虚拟主##################################
httpd支持的虚拟主机类型包括以下三种。
基于域名:为每个虚拟主机使用不同的域名,但是其对于的ip地址是相同的。
基于IP地址:为每个虚拟主机使用不同的域名,且各自对于的ip地址也不相同。
基于端口:不使用域名,IP地址来区分不同的站点内容,而是使用了不同的TCP端口号。
`

#################################基于IP地址的虚拟主机#########################

####开启虚拟机主机功能模块####

vi /usr/local/httpd/conf/httpd.conf
#Listen localhost:80 #必须禁用
#Virtual hosts
Include conf/extra/httpd-vhosts.conf #这行前面的#去掉 vhosts模块生效
`
cd /usr/local/httpd/conf/extra/
vi httpd-vhosts.conf


######为了直接显示源代码,在后面添加ab、aa为主页文件##
vi /usr/local/httpd/httpd.conf
**<IfModule dir_module>**
DirectoryIndex index.html ab.html aa.html
**</IfModule>**

####默认的实列#去掉####
#:80>
#ServerAdmin [email protected]
#DocumentRoot "/usr/local/httpd/docs/dummy-host.example.com"
#ServerName dummy-host.example.com
#ServerAlias www.dummy-host.example.com
#ErrorLog "logs/dummy-host.example.com-error_log"
#CustomLog "logs/dummy-host.example.com-access_log" common
#

`
#:80>

#ServerAdmin [email protected]
#DocumentRoot "/usr/local/httpd/docs/dummy-host2.example.com"
#ServerName dummy-host2.example.com
#ErrorLog "logs/dummy-host2.example.com-error_log"
#CustomLog "logs/dummy-host2.example.com-access_log" common
#
`

###########基于IP地址的虚拟主机##########
Listen 192.168.10.11:80 ####必须要开启监听


ServerAdmin [email protected] ####设置http服务器管理员的E-mail地址,可以通过E-mail地址联系WEB站点的管理员
DocumentRoot /opt/aa/ ####设置网站跟目录,即网页在系统中存放的路径
ServerName www.aa.com ####设置网站的完整主机名,即(主机名+域名)
ErrorLog logs/aa.com-error_log ####错误日志存放路径
CustomLog logs/aa.com-access_log common ####访问日志文件路劲

####区域配置的根目录 是/opt/aa目录
Options Indexes FollowSymLinks ###基础配置
AllowOverride All ######允许所有主机
Require all granted ####允许所有主机访问

Listen 192.168.20.11:80

ServerAdmin [email protected]
DocumentRoot /opt/ab/
ServerName www.ab.com
ErrorLog logs/ab.com-error_log
CustomLog logs/ab.com-access_log common


Options Indexes FollowSymLinks
AllowOverride All
Require all granted


######验证#####
service httpd restart
登录客户端的浏览器测试!!!
测试2个地址:
1、192.168.10.11
2、192.168.20.11

###################################基于端口号################################
Listen 192.168.10.11:80


ServerAdmin [email protected]
DocumentRoot /opt/aa/
ServerName www.aa.com
ErrorLog logs/aa.com-error_log
CustomLog logs/aa.com-access_log common


Options Indexes FollowSymLinks
AllowOverride All
Require all granted

Listen 192.168.10.11:8080

ServerAdmin [email protected]
DocumentRoot /opt/ab/
ServerName www.ab.com
ErrorLog logs/ab.com-error_log
CustomLog logs/ab.com-access_log common


Options Indexes FollowSymLinks
AllowOverride All
Require all granted

`
######验证#####
service httpd restart
登录客户端的浏览器测试!!!
测试2个地址:
1、192.168.10.11:80
2、192.168.10.11:8080

###########################基于域名的虚拟主机###################
Listen 192.168.10.74:80
`
*:80>
ServerAdmin [email protected]
DocumentRoot /opt/aa/
ServerName www.aa.com
ErrorLog logs/aa.com-error_log
CustomLog logs/aa.com-access_log common
**


Options Indexes FollowSymLinks
AllowOverride all
Require all granted

*:80>
ServerAdmin [email protected]
DocumentRoot /opt/ab/
ServerName www.ab.com
ErrorLog logs/ab.com-error_log
CustomLog logs/ab.com-access_log common
**


Options Indexes FollowSymLinks
AllowOverride All
Require all granted

######验证#####
service httpd restart
登录客户端的浏览器测试!!
####
客户端需要在hosts文件添加域名解析:

192.168.10.11 www.aa.com
192.168.10.11 www.ab.com

####
测试2个地址:
1、www.aa.com
2、www.ab.com