虚拟目录简介:
虚拟目录就是将原本不存在于网站根目录下的目录映射到一个别名上,这样Apache就可以通过“http(s)://网址/别名”的形式访问他啦!
配置方法:
先配置一个简单的虚拟主机。
[root@localhost ~]# vim /etc/httpd/conf.d/a.conf <VirtualHost *:80> DocumentRoot /tmp/html/ </VirtualHost>
在虚拟主机中定义虚拟目录。
Alias /dir /tmp/html1
最终的虚拟机配置文件的内容是这样的。
<VirtualHost *:80> DocumentRoot /tmp/html/ Alias /dir /tmp/html1 </VirtualHost>
创建站点目录及网页。
[root@localhost ~]# mkdir /tmp/html /tmp/html1 [root@localhost ~]# echo one > /tmp/html/index.html [root@localhost ~]# echo two > /tmp/html1/index.html
在保证selinux和防火墙均关闭的情况下启动Apache。
[root@localhost ~]# service httpd start
测试:
可以选择在Windows的浏览器上测试,这里我为了方便,直接在CentOS下的文本浏览器中测试。
安装浏览器。
[root@localhost ~]# yum install -y links
使用浏览器打开站点首页,这里的192.168.1.100是我的Apache服务器的IP地址。
[root@localhost ~]# links 192.168.1.100
按q退出后,重新打开带虚拟目录的站点URL,可以看到,成功输出了虚拟目录中的首页文件的内容,至此,虚拟目录配置完成。
[root@localhost ~]# links 192.168.1.100/dir