【问题标题】:In Apache Server,does making the virtualhost enabled mean the 'Mainhost' is disabled?在 Apache 服务器中,启用虚拟主机是否意味着禁用“主主机”?
【发布时间】:2013-09-04 06:23:36
【问题描述】:

我正在配置我的 apache 服务器。在 httpd.conf 中,我将 DocumentRoot 设置如下:

DocumentRoot "D:/phpwwwroot"

我将目录节点设置如下:

<Directory "D:/phpwwwroot">
    Options Indexes FollowSymLinks
    AllowOverride All
   Order allow,deny
    Allow from all
</Directory>

目前,我还没有启用虚拟主机。我访问了网址:http://localhost:8080/,一切正常。

接下来,我尝试设置虚拟主机。我取消了虚拟主机的注释。如下:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

而我的 httpd-vhosts.conf 如下:

NameVirtualHost *:8080

<VirtualHost *:8080>
    ServerName www.testphp1.com
    DocumentRoot "D:\VirtualRoot"
    DirectoryIndex index.shtml index.html index.htm index.php  
    <Directory "D:\VirtualRoot">  
        Options Indexes FollowSymLinks 
        AllowOverride all  
        Order allow,deny  
        Allow from all  
    </Directory>  
</VirtualHost>

<VirtualHost *:8080>
    ServerName www.testphp2.com
    DocumentRoot "D:\VirtualRoot1"
    DirectoryIndex index.shtml index.html index.htm index.php  
    <Directory "D:\VirtualRoot1">  
        Options Indexes FollowSymLinks 
        AllowOverride all  
        Order allow,deny  
        Allow from all  
    </Directory>  
</VirtualHost>

而且我还编辑了 hosts 文件以更正映射,你应该知道我的意思:

127.0.0.1 www.testphp1.com
127.0.0.1 www.testphp2.com

接下来重启apache服务器,访问下面的url:

http://www.testphp1.com:8080/
http://www.testphp2.com:8080/

一切正常。它们被映射到正确的文件夹。

提出了一个新问题,当我尝试访问http://localhost:8080/ 时,它来到了第一个虚拟主机--www.testphp1.com。我的意思是页面显示了www.testphp1.com 显示的内容。

“主宿主”好像不行了。

它是如何发生的?如何解决它

【问题讨论】:

    标签: php apache virtualhost


    【解决方案1】:

    使用 IP 访问服务器时也是如此。它将显示使用此 IP 的第一个活动网站(localhost 在此处被视为 IP)。您可以通过先定义主网站来修复它。

    【讨论】:

      【解决方案2】:

      您还需要添加主主机,例如:

      <VirtualHost *:8080>
          ServerName localhost
          DocumentRoot "D:/phpwwwroot"
      
      </VirtualHost>
      

      【讨论】:

      • 所以,这意味着 httpd.conf 中的 Main 主机不再有用,不是吗?也就是说,如果我们设置了虚拟主机,那么主主机可以认为是不存在的。
      猜你喜欢
      • 2015-08-13
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 2013-08-02
      • 2018-06-26
      • 2019-10-01
      • 2011-06-19
      • 2020-04-14
      相关资源
      最近更新 更多