虚拟主机带通配符VirtualDocumentRoot [英] VirtualHost with wildcard VirtualDocumentRoot

查看:1093
本文介绍了虚拟主机带通配符VirtualDocumentRoot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建我的虚拟主机备用。我的配置是这样的:

I'm trying to create a fallback for my virtual hosts. My configuration looks like this:

# Fetch all pre-defined hosts

Include "conf/extra/vhosts/*.conf"

# Fallback

NameVirtualHost *:80

<Directory "C:/LocalServer/usr">
    Options Indexes FollowSymLinks Includes
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    VirtualDocumentRoot "C:/LocalServer/usr/%-1/projects/%-2+/public/"
</VirtualHost>

这里的目的是:如果我试图访问 HTTP://test.lab/ ,我希望它会自动拿起以下目录: C:/的LocalServer的/ usr /实验室/工程/测试/公/

The objective here is the following: If I try to access http://test.lab/, I want it to automatically pick up the following directory: C:/LocalServer/usr/lab/projects/test/public/.

现在,我已经创建的文件夹,一个空的索引文件(的index.php )。然而,阿帕奇不断出现我一个空目录指数(指数)。

Now, I have created the folders, and an empty index file (index.php). Nonetheless, Apache keeps showing me an empty Directory Index ("Index of").

没有很确定现在做什么。已经尝试了一些东西,其中没有一个似乎工作。

No quite sure what to do now. Have tried a few things, none of which seem to work.

任何想法?

我现在用这个code的基础上,第一个答案(当然,唯一的一个):

I am now using this code, based on the first answer (well, the only one):

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAlias *.lab
    VirtualDocumentRoot "C:/LocalServer/%2/%1/public"
    <Directory "C:/LocalServer/%2/%1/public">
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

我现在得到来自Apache的使用禁止错误。一个肯定,通常情况下,收到此错误时,目录不存在? C:/的LocalServer /实验室/测试/公确实存在,而且一个空的的index.php 驻留在公共目录。

I now get an Access forbidden error from Apache. One would surely, normally, receive this error when the directory does not exist? C:/LocalServer/lab/test/public does exist, and an empty index.php resides in the public directory.

在一般的错误日志中的错误: [客户127.0.0.1:49342] AH01797:客户机通过服务器配置否认:C:/的LocalServer /实验室/测试/公/

The error in the general error log: [client 127.0.0.1:49342] AH01797: client denied by server configuration: C:/LocalServer/lab/test/public/

如果我删除&LT;目录/&GT; 组,没有什么变化。我仍然得到错误。 (我甚至可以用%N 在该组?)

If I remove the <Directory/> group, nothing changes. I still get the error. (Can I even use %n in that group?)

这是以前没有工作的原因是由于这样的事实,我已经被导入其他虚拟主机,由包含的conf /额外/虚拟主机/ *。CONF指令。注释出来(从而使实验室的统治只有一个)开始在禁止访问错误

The reason it wasn't working before was due to the fact that I had other Virtual Hosts being imported, by means of the Include "conf/extra/vhosts/*.conf" instruction. Commenting it out (and thus making the Labs rule the only one) initiated the Access forbidden error.

另外请注意,我不再使用 USR 文件夹 - 现在每个实验室是在实验室文件夹,在的LocalServer

Also note that I am no longer using the usr folder - each Lab is now in the lab folder, under LocalServer.

看来,&LT;目录/&GT; 块不允许变量插入,如 VirtualDocumentRoot 一样。

It seems that the <Directory/> block does not allow for variables to be inserted, like VirtualDocumentRoot does.

这是现在的工作 - 不会已经能够做到这一点没有帮助。下面是最终code:

It is now working - would not have been able to do it without the help. Here's the final code:

<VirtualHost lab:80>
    UseCanonicalName Off
    ServerAlias *.lab
    VirtualDocumentRoot "C:/LocalServer/%2/%1/public"
    <Directory "C:/LocalServer/lab/*/public">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
    </Directory>
</VirtualHost>

更新4(2015年4月)

新的指令,对于那些有兴趣(使用最新版的Apache 2.4):

<VirtualHost *:80>
    UseCanonicalName Off
    ServerAlias *.local
    VirtualDocumentRoot "D:/home/%-2+/public_html"
    <Directory "D:/home/*/public_html">
        Require all granted
        AllowOverride All
        Options Indexes FollowSymLinks
    </Directory>
</VirtualHost>

这与亚克力DNS代理的结合,使得魔术

推荐答案

我使用它们:)你忘了关掉的规范名称 - 不幸的是,我不知道为什么,必须有我的配置ServerAlias​​ - 它只是不会没有它的工作 - code以下测试和工作

I use them :) You forgot about switching off canonical names - unfortunately I don't know why there must be ServerAlias in my configuration - it just won't work without it - code below is tested and working

<Directory "C:/LocalServer/*/public">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    Require local
</Directory>

<VirtualHost *:80>
    # Apache will form URLs using the hostname supplied by the client
    UseCanonicalName Off

    # available aliases to use
    ServerAlias *.lab *.lab2

    # where to put them
    VirtualDocumentRoot "C:/LocalServer/%2/%1/public/"
</VirtualHost>

这篇关于虚拟主机带通配符VirtualDocumentRoot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆