简体   繁体   English

设置 Virtualhosts 后 localhost 不起作用

[英]localhost doesn't work, after setup Virtualhosts

I think I made a rookie mistake.我想我犯了一个菜鸟的错误。 But can't fix it.但无法修复。

I set up two VirtualHosts in httpd.我在 httpd 中设置了两个 VirtualHost。 Content, each index.html, is located at /www/docs/Domain1 and.. /Domain2 The.conf files from the two domains are located in /etc/httpd/conf.d/domain1.conf and /domain2.conf.内容,每个index.html,分别位于/www/docs/Domain1/Domain2这两个域的.conf文件分别位于/etc/httpd/conf.d/domain1.conf/domain2.conf.

httpd.conf is adapted accordingly. httpd.conf 进行了相应的调整。

I expanded /etc/hosts with:我扩展了/etc/hosts

192.168.167.64 sales.test.pri sales 192.168.167.64 account.test.pri account

http://sales.test.pri and http://account.test.pri in browser works. http://sales.test.prihttp: //account.test.pri 在浏览器中工作。 The correct content is displayed.显示正确的内容。

With http://localhost or http://192.168.167.64 , I still get the content from one of the VirtualHosts.使用http://localhosthttp://192.168.167.64 ,我仍然可以从其中一个虚拟主机中获取内容。 Usually the content of /var/www/html/index.html should appear.通常应该出现/var/www/html/index.html的内容。 That worked before setting up vHosts.这在设置 vHost 之前有效。

What am I doing wrong?我究竟做错了什么?

Apache will decide which VirtualHost to use with the IP, Port or domain name. Apache 将决定哪个 VirtualHost 与 IP、端口或域名一起使用。

If it cannot match any VirtualHost, it will use the default one.如果它不能匹配任何 VirtualHost,它将使用默认的。

The default one is the first one it finds, as it reads the config file from top to bottom.默认的是它找到的第一个,因为它从上到下读取配置文件。 So add another VirtualHost on top that points to /var/www/html/index.html .因此,在顶部添加另一个指向/var/www/html/index.html的 VirtualHost 。 Or create a new VirtualHost for localhost of the IP address.或者为 IP 地址的 localhost 创建一个新的 VirtualHost。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM