windows 在虚拟主机内创建别名目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12879298/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:58:49  来源:igfitidea点击:

Create an Alias Directory inside a Virtual Host

windowsapache2aliasvirtualhostwampserver

提问by Praveen Kumar Purushothaman

I checked here, here, here, here, and herebefore asking this question. I guess my search skills are weak.

在问这个问题之前,我检查了这里这里这里这里这里。我想我的搜索技巧很弱。

I am using the WampServerversion 2.2e. I have a need like, I need a virtual path inside a virtual host. Let me say the two hosts that I have.

我正在使用WampServer版本2.2e。我有一个需求,我需要一个虚拟主机内的虚拟路径。让我说我拥有的两个主机。

Primary Virtual Host (Localhost)

主要虚拟主机 (Localhost)

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "C:/Wamp/www"
</VirtualHost>

My Apps Virtual Hosts

我的应用程序虚拟主机

<VirtualHost *:80>
    ServerName apps.ptrl
    DocumentRoot "C:/Wamp/vhosts/ptrl/apps"
    ErrorLog "logs/apps-ptrl-error.log"
    CustomLog "logs/apps-ptrl-access.log" common
    <Directory "C:/Wamp/vhosts/ptrl/apps">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
    DirectoryIndex index.html index.htm index.php
</VirtualHost>

My Blog Virtual Host

我的博客虚拟主机

<VirtualHost *:80>
    ServerName blog.praveen-kumar.ptrl
    DocumentRoot "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"
    ErrorLog "logs/praveen-kumar-ptrl-error.log"
    CustomLog "logs/praveen-kumar-ptrl-access.log" common
    <Directory "C:/Wamp/vhosts/ptrl/praveen-kumar/blog">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
    DirectoryIndex index.html index.htm index.php
</VirtualHost>

My requirement now is to have http://apps.ptrl/blog/and http://blog.praveen-kumar.ptrl/should be the same directory. One thing I thought of is, moving the blogfolder inside the appsfolder, but it is connected with Gitand other stuffs are there, so it is not possible to move the folder.

我现在的要求是拥有http://apps.ptrl/blog/并且http://blog.praveen-kumar.ptrl/应该是同一个目录。我想到的一件事是,将blog文件夹移动到文件夹内apps,但它是连接的Git,其他东西都在那里,因此无法移动文件夹。

So, I thought of creating an aliasto the VirtualHostin this way:

所以,我想以这种方式创建一个aliasVirtualHost

<VirtualHost *:80>
    ServerName apps.ptrl
    DocumentRoot "C:/Wamp/vhosts/ptrl/apps"
    ErrorLog "logs/apps-ptrl-error.log"
    CustomLog "logs/apps-ptrl-access.log" common
    <Directory "C:/Wamp/vhosts/ptrl/apps">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
    DirectoryIndex index.html index.htm index.php

    # The alias to the blog!
    Alias /blog "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"
    <Directory "C:/Wamp/vhosts/ptrl/praveen-kumar/blog">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
</VirtualHost>

But when I tried to access http://apps.ptrl/blog, I am getting an Error 403 Forbiddenpage.

但是当我尝试访问时http://apps.ptrl/blog,我得到了一个Error 403 Forbidden页面。

Forbidden

禁止的

Am I doing the right thing? If you need to look at the access log, and error log, they are here:

我在做正确的事吗?如果您需要查看访问日志和错误日志,它们在这里:

# Access Log
127.0.0.1 - - [14/Oct/2012:09:53:11 +0530] "GET /blog HTTP/1.1" 403 206
127.0.0.1 - - [14/Oct/2012:09:53:11 +0530] "GET /favicon.ico HTTP/1.1" 404 209
127.0.0.1 - - [14/Oct/2012:09:53:53 +0530] "GET / HTTP/1.1" 200 6935
127.0.0.1 - - [14/Oct/2012:09:53:53 +0530] "GET /app/blog/thumb.png HTTP/1.1" 404 216
# Error Log
[Sun Oct 14 09:53:11 2012] [error] [client 127.0.0.1] client denied by server configuration: C:/Wamp/vhosts/ptrl/praveen-kumar/blog
[Sun Oct 14 09:53:11 2012] [error] [client 127.0.0.1] File does not exist: C:/Wamp/vhosts/ptrl/apps/favicon.ico
[Sun Oct 14 09:53:53 2012] [error] [client 127.0.0.1] File does not exist: C:/Wamp/vhosts/ptrl/apps/app/blog, referer: http://apps.ptrl/

Waiting eagerly for some help. I am ready to provide more info, if needed.

急切地等待一些帮助。如果需要,我准备提供更多信息。



Update #1: Changed VirtualHosts declaration according to the instructions given by felipsmartins:

更新 #1:根据felipsmartins给出的说明更改了 VirtualHosts 声明:

<VirtualHost *:80>
    ServerName apps.ptrl
    DocumentRoot "C:/Wamp/vhosts/ptrl/apps"
    ErrorLog "logs/apps-ptrl-error.log"
    CustomLog "logs/apps-ptrl-access.log" common
    # The alias to the blog!
    Alias /blog "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"
    <Directory "C:/Wamp/vhosts/ptrl/praveen-kumar/blog">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
    <Directory "C:/Wamp/vhosts/ptrl/apps">
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
    DirectoryIndex index.html index.htm index.php
</VirtualHost>


Update #2: Another Issue:

更新 #2:另一个问题:

I am able to access the site. The physical links are working now. i.e., I am able to open http://apps.ptrl/blog/index.phpbut not http://apps.ptrl/blog/view-1.ptf, which gets translated to http://apps.ptrl/blog/index.php?page=view&id=1. Any solutions?

我可以访问该网站。物理链接现在正在工作。即,我可以打开http://apps.ptrl/blog/index.php但不能打开http://apps.ptrl/blog/view-1.ptf,它被转换为http://apps.ptrl/blog/index.php?page=view&id=1. 任何解决方案?

回答by felipsmartins

Note, if you are creating an Aliasto a directory outside of your DocumentRoot, you may need to explicitly permit access to target directory:

请注意,如果您要为DocumentRoot之外的目录创建别名,则可能需要明确允许访问目标目录:

<VirtualHost *:80>
    ServerName apps.ptrl
    DocumentRoot "C:/Wamp/vhosts/ptrl/apps"
    ErrorLog "logs/apps-ptrl-error.log"
    CustomLog "logs/apps-ptrl-access.log" common

    # Puts here, before Directory directive :) 
    Alias /blog "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"

    <Directory "C:/Wamp/vhosts/ptrl/apps">        
        allow from all
        order allow,deny
        AllowOverride All
    </Directory>
</VirtualHost>

Note, too, that URL-path (first Alias part) is case-sensitive even on case-insensitive file systems.

还要注意,即使在不区分大小写的文件系统上,URL 路径(第一个别名部分)也是区分大小写的。

Also, check permissions from C:/Wamp/vhosts/ptrl/praveen-kumar/blogdirectory.

另外,检查C:/Wamp/vhosts/ptrl/praveen-kumar/blog目录的权限。

Reference

参考