这是我的vhosts.conf
<VirtualHost *:80> DocumentRoot "C:/wamp/www" ServerName localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/wamp/www/images" ServerName images.localhost </VirtualHost> <VirtualHost *:80> DocumentRoot "C:/wamp/www/project" ServerName project.localhost </VirtualHost> Listen 8080 <VirtualHost *:8080> DocumentRoot "C:/wamp/www/trunk" ServerName localhost </VirtualHost> <VirtualHost *:8080> DocumentRoot "C:/wamp/www/images2" ServerName images2.localhost </VirtualHost>
这是我的Windows主机文件
127.0.0.1 project.localhost 127.0.0.1 images.localhost 127.0.0.1 images2.localhost
所以前三个都没问题 8080端口上的本地主机工作,我只是去本地主机:8080,它加载了什么是在主干。
images2.localhost:8080显示了C:/ wamp / www / trunk里面的内容,而images2.localhost只是进入了wampserver主页面。 试图改变这一点,但它仍然是一样的。
为了增加一点清晰度,这些条目中的第一个“拥有”:8080端口,所以第二个被忽略。
<VirtualHost *:8080> DocumentRoot "C:/wamp/www/trunk" ServerName localhost </VirtualHost> <VirtualHost *:8080> DocumentRoot "C:/wamp/www/images2" ServerName images2.localhost </VirtualHost>
你想要的是基于名称的虚拟服务器,所以你可以使第一和第二个条目是唯一的。 这是什么使ServerName指令实际上做一些事情。 如@quanta所述,将NameVirtualHost *:8080添加到configuration中,然后Apache将注意您在浏览器中input的url,并根据与URL匹配的ServerName指令提供页面。
插入NameVirtualHost *:8080指令NameVirtualHost *:8080试。