概述:
虚拟目录:指在站点下建立一个虚拟子目录,指定一个固定的物理路径做为站点的应用路径。每个Internet服务可以从多个目录中发布。虚拟服务器可拥有一个宿主目录和任意数量的其它发布目录。其它发布目录称为虚拟目录。
虚拟主机分为:
1.基于域名的虚拟主机(不同域名相同IP和端口)
向DNS服务提供虚拟Web站点的域名,以便当访问其中任何一个虚拟Web站点时,最终访问的都是同一个IP地址。
2.基于端口的虚拟主机(不同端口相同IP)
通常只用于同一个Web站点,其网站的名称、IP地址往往是相同的,但通过不同的TCP端口来提供访问不同网页内容的服务入口。在浏览器中访问非80端口的Web服务器时,需要明确指出服务器的端口号。
实验步骤:
(一).虚拟目录
1.查看httpd是否安装以及查看httpd.conf的主配置文件

2.到/etc/httpd/conf/httpd.conf 的主配置文件中修改Listen监听地址和ServerName域名


3.启动httpd服务并关闭防火墙和增强性安全功能

4.切换到/etc/httpd/conf.d,在 vdir.conf配置文件中创建虚拟目录test。

5.输入mkdir /opt/test创建test目录并切换到/opt目录中,写入echo "this is vdir test" > /opt/test/index.html

6.重启httpd服务,打开浏览器输入192.168.100.100/test进行验证


7.进入 vdir.conf配置文件中开启用户验证并设置用户密码


8.重启httpd服务,打开浏览器进行验证。


(二).不同域名相同IP、端口。
1.在etc/httpd/conf.d/目录中创建 host.conf文件在host文件中分别创建域名benet、accp。

2.创建站点目录,切换到/opt目录中分别在benet、accp首页中写入this is accp和this is benet。

3.搭建DNS服务进行域名解析,安装bind包。

4.编辑主配置文件vim /etc/named.conf ,修改监听地址并设置所有网段都能进行解析。

5.编辑区域配置文件 vim /etc/named.rfc1912.zones

6.切换到/var/named/目录下,保留原文件属性把区域数据配置模板named.localhost复制到benet.com.zone、accp.com.zone配置文件中,分别进行编辑。



7.启动named服务和重启httpd服务进行解析验证



(三).不同端口相同IP
1.切换到/etc/httpd/conf.d/目录中,在host.conf 文件中插入8080端口。


2.创建站点目录benet01,切换到/opt目录中

3.编辑/etc/httpd/conf/httpd.conf配置文件,加入监听地址和端口8080.

4.重启httpd服务并查看端口信息

5.在浏览器上输入www.benet.com:8080进行验证

Apache虚拟目录和多端口多主机名配置
原文:http://blog.51cto.com/13642258/2126743