【问题标题】:Using a directory in VirtualHost ServerName使用 VirtualHost ServerName 中的目录
【发布时间】:2011-07-29 22:53:41
【问题描述】:

我目前正在使用基于名称的虚拟主机配置,从同一 IP 地址为大约 5 个不同的网站提供服务器,就像在 apache 文档中一样:

<VirtualHost *:80>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

是否有可能有类似的东西:

<VirtualHost *:80>
ServerName www.domain.tld/folderpath
DocumentRoot /www/software
</VirtualHost>

此文件夹中的网页使用不同的软件堆栈,我想将其很好地分开。上面的方法我试过了,还是不行。

【问题讨论】:

    标签: apache virtualhost


    【解决方案1】:

    不可能以您的方式显示 - VirtualHost 始终只是主机。但你可以使用Alias

    <VirtualHost *:80>
    ServerName www.domain.tld
    DocumentRoot /www/domain
    
    Alias /folderpath /www/software
    
    </VirtualHost>
    

    【讨论】:

    • 甜蜜。出于荒谬无法解释的原因,这正是我所需要的。
    • 知道如何撤消此操作吗?我做了别名,效果很好。现在我不再需要它,所以我删除了它,但服务器一直在尝试记住它。全部解释在这里:stackoverflow.com/questions/38042221/…
    • @eimajen 那该网站将如何被访问? www.domain.tld/软件?我有一个域,但我希望当它访问 mydomain.com 时它应该打开一个 php 应用程序的网站,但是当访问 mydomain.com/yesmo 时它应该打开我的另一个 node.js 应用程序。所以我正在考虑使用您解释的别名进行相同的配置。
    【解决方案2】:

    是否可以像这样为每个应用程序设置不同的虚拟主机:

    <VirtualHost *:80>
    ServerName www.domain.tld
    DocumentRoot /www/domain
    </VirtualHost>
    
    <VirtualHost *:80>
    ServerName www.domain.tld
    Alias otherApp /www/otherApp
    </VirtualHost>

    【讨论】:

    • 这将不起作用,因为 Apache 将始终选择与 ServerName 指令匹配的第一个虚拟主机。第二个虚拟主机将不会被使用,因此 Alias 指令将无效。因此,任何对 www.domain.ltd/otherApp 的调用都会发出 http 404 not found 错误。
    • 如果我们颠倒顺序会起作用吗?所以它会先找到“www.domain.ltd/otherApp”,如果没有找到“www.domain.ltd”?
    【解决方案3】:

    我添加到alias.conf 文件(在 Windows 机器上)。
    请记住,如果它在“文档根”路径之外,您将需要权限

    <IfModule alias_module>
    
        #### FolderPath ####
        Alias /folderpath "E:/any/path/you/like"
    
        <Directory "E:/any/path/you/like">
            Options Indexes MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    
        #### Another ####
        Alias /another "E:/another/different/path"
    
        <Directory "E:/another/different/path">
            Options Indexes MultiViews
            AllowOverride None
            Order allow,deny
            Allow from all
        </Directory>
    
    </IfModule>
    

    【讨论】:

      猜你喜欢
      • 2014-12-30
      • 2016-10-02
      • 2013-06-26
      • 1970-01-01
      • 2015-02-21
      • 2013-12-21
      • 1970-01-01
      • 2011-06-17
      • 1970-01-01
      相关资源
      最近更新 更多