目录
一:基于不同的IP地址
二:基于不同的端口
三:基于不同的域名
一:基于不同的IP地址
步骤一:修改主配置文件
vim /usr/local/apache/conf/httpd.conf
声明监听不同的IP地址的80端口
Listen 192.168.2.20:80
Listen 192.168.2.30:80
开启使用虚拟主机文件的选项
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
步骤二:配置定义默认访问主页
vim /usr/local/apache/htdocs
mkdir hy1 mkdir hy2
cp index.html hy1
cp indes.heml hy2
分别键入内容,以便下步验证
例:hy1--index.html
例:hy2--index.html
步骤三:主配置文件包含虚拟主机配置文件
vim /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.2.20:80>
DocumentRoot "/usr/local/apache/htdocs/hy1"
#ServerName dummy-host.example.com
#ServerAlias www.dummy-host.example.com
ErrorLog "logs/2.20-error_log"
CustomLog "logs/2.20-access_log" common
<VirtualHost 192.168.2.30:80>
DocumentRoot "/usr/local/apache/htdocs/hy2"
#ServerName dummy-host2.example.com
ErrorLog "logs/2.30-error_log"
CustomLog "logs/2.30-access_log" common
步骤四:启动服务
apachectl start
步骤五:
验证:
192.168.2.20
192.168.2.30
二:基于不同的端口
步骤一:修改主配置文件
vim /usr/local/apache/conf/httpd.conf
声明监听不同的IP地址的80端口
Listen 192.168.2.20:8081
Listen 192.168.2.20:8081
开启使用虚拟主机文件的选项
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
步骤二:配置定义默认访问主页
vim /usr/local/apache/htdocs
mkdir hy1 mkdir hy2
cp index.html hy1
cp indes.heml hy2
分别键入内容,以便下步验证
例:hy1--index.html
例:hy2--index.html
步骤三:主配置文件包含虚拟主机配置文件
vim /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost 192.168.2.20:8081>
DocumentRoot "/usr/local/apache/htdocs/hy1"
#ServerName dummy-host.example.com
#ServerAlias www.dummy-host.example.com
ErrorLog "logs/8081-error_log"
CustomLog "logs/8081-access_log" common
<VirtualHost 192.168.2.20:8082>
DocumentRoot "/usr/local/apache/htdocs/hy2"
#ServerName dummy-host2.example.com
ErrorLog "logs/8082-error_log"
CustomLog "logs/8082-access_log" common
步骤四:启动服务
apachectl start
步骤五:
验证:
192.168.2.20:8081
192.168.2.20:8082
三:基于不同的域名
步骤一:安装dns域名解析
yum -y install bind
配置dns主配置文件
vim /etc/named.conf
配置dns区域配置文件
vim /etc/named.rfc1912.zones
配置数据文件
正向解析:
vim /var/named/hy.localhost
反向解析:
vim /var/named/hy.empty
步骤二:修改主配置文件
vim /usr/local/apache/conf/httpd.conf
声明监听不同的IP地址的80端口
Listen 192.168.2.20:80
开启使用虚拟主机文件的选项
# Virtual hosts
# Include conf/extra/httpd-vhosts.conf
步骤三:配置定义默认访问主页
vim /usr/local/apache/htdocs
mkdir hy1 mkdir hy2
cp index.html hy1
cp indes.heml hy2
分别键入内容,以便下步验证
例:hy1--index.html
例:hy2--index.html
步骤四:主配置文件包含虚拟主机配置文件
vim /usr/local/apache/conf/extra/httpd-vhosts.conf
<VirtualHost dns.hy.com:80>
DocumentRoot "/usr/local/apache/htdocs/hy1"
ServerName dummy-dns.hy.com
#ServerAlias www.dummy-host.example.com
ErrorLog "hy-error_log"
CustomLog "hy-access_log" common
<VirtualHost www.hy.com:80>
DocumentRoot "/usr/local/apache/htdocs/hy2"
ServerName dummy-www.hy.com
ErrorLog "hy-error_log"
CustomLog "hy-access_log" common
步骤五:启动服务
apachectl start
步骤六:
验证:
dns.hy.com
www.hy.com