一个apache服务器的vhost.conf配置文件可以设置Apache监听多个端口,打开Apache的配置文件httpd.conf,在
Listen 80
下面添加多个监听端口如:
Listen 8010
Listen 8020
Listen 8030
这样就在vhosts.conf配置文件中增加了8010、8020和8030端口的监听,然后在最后的位置设置虚拟主机目录:
<VirtualHost *:8010>DocumentRoot "D:\phpStudy\WWW\juye"ServerName www.juye.comServerAlias <Directory "D:\phpStudy\WWW\juye">Options FollowSymLinks ExecCGIAllowOverride AllOrder allow,denyAllow from allRequire all granted</Directory>
</VirtualHost><VirtualHost *:8020>DocumentRoot "D:\phpStudy\WWW\fengcheng"ServerName www.fengcheng.comServerAlias <Directory "D:\phpStudy\WWW\fengcheng">Options FollowSymLinks ExecCGIAllowOverride AllOrder allow,denyAllow from allRequire all granted</Directory>
</VirtualHost><VirtualHost *:8030>DocumentRoot "D:\phpStudy\WWW\swcati_yingtan"ServerName www.yingtan.comServerAlias <Directory "D:\phpStudy\WWW\swcati_yingtan">Options FollowSymLinks ExecCGIAllowOverride AllOrder allow,denyAllow from allRequire all granted</Directory>
</VirtualHost>
之后,通过重启apache服务器。然后在浏览器分别访问(hosts中已添加)
www.juye.com:8010
www.fengcheng.com:8020
www.yingtan.com:8030
即可访问对应的项目。但是,如果不添加端口号,会访问根目录,这是为什么?原来我还添加了一个默认访问的vhost.conf配置:
<VirtualHost _default_:80>
DocumentRoot "D:\phpStudy\WWW"<Directory "D:\phpStudy\WWW">Options +Indexes +FollowSymLinks +ExecCGIAllowOverride AllOrder allow,denyAllow from allRequire all granted</Directory>
</VirtualHost>
把这个配置删除后,再次不加端口进行访问时,却是禁止访问了: