【问题标题】:need help with xampp virtual host在 xampp 虚拟主机方面需要帮助
【发布时间】:2011-11-08 09:43:42
【问题描述】:

我正在使用 XAMPP,Apache 2.2.17。我添加了虚拟主机,但我的虚拟主机和本地主机都指向同一个位置。这是我在 httpd-vhosts.conf 中的代码

<VirtualHost www.domain.tld:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot "C:/xampp/htdocs/workspace/testsite"
</VirtualHost>

<VirtualHost *:80>
   DocumentRoot "C:/xampp/htdocs/xampp"
   ServerAlias localhost
   ServerName localhost
</VirtualHost>

通过上面的代码,我得到了带有 www.domain.tld 的测试站点,这很好。但是如果我输入 localhost,它也会进入测试站点。如果我在测试站点之前移动,那么 localhost 会转到 localhost good 并且 www.domain.tld 也会转到 localhost。我尝试了 localhost 的不同设置,就像

<VirtualHost *>
<VirtualHost localhost:80>

并从 domain.tld 中删除 *.domain.tld 但没有任何效果。我错过了什么明显的东西吗?

【问题讨论】:

    标签: xampp virtualhost


    【解决方案1】:
    NameVirtualHost *:80
    
    <VirtualHost *:80>
        DocumentRoot C:/xampp/htdocs
        ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName mydomain.local
        ServerAlias www.mydomain.local 
        DocumentRoot C:/mysite/htdocs
    </VirtualHost>
    

    【讨论】:

    【解决方案2】:

    我自己的回答:下面的代码解决了这个问题

    <VirtualHost *:80> <--- * fixed the problem, apache 2.2 doc does say it must match www.domain.tld, which caused problem for other Virtual hosts
    ServerName www.domain.tld
    ServerAlias domain.tld 
    DocumentRoot "C:/xampp/htdocs/workspace/patriot2"
    </VirtualHost>
    
    <VirtualHost *:80>
       DocumentRoot "C:/xampp/htdocs/xampp"
       ServerAlias localhost
       ServerName localhost
    </VirtualHost>
    

    【讨论】:

    【解决方案3】:

    请将您的 ServerName 从 virtualhost 更改为本地 IP 地址,例如 127.0.0.2。

    ServerName domain.tld 是使用“domain.com”的示例,其中 .tld 被替换为您的域的 .com。

    【讨论】:

    • 我之前尝试过 127.0.0.1 但没有成功。再试一次,没用 + 试过 ,没用。
    猜你喜欢
    • 2021-02-10
    • 2015-09-24
    • 2011-01-27
    • 2014-02-06
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多