在虚拟主机内创建一个别名目录 [英] Create an Alias Directory inside a Virtual Host

查看:318
本文介绍了在虚拟主机内创建一个别名目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查<一href=\"http://stackoverflow.com/questions/5552081/using-a-directory-in-virtualhost-servername\">here, 这里,<一个href=\"http://www.nodans.com/index.cfm/2006/10/10/Apache-Directory-Aliases-and-Virtual-Directories\">here, 这里和的问这个问题之前,这里。我想我的搜索能力较弱。

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

我使用的是 WampServer 版本 2.2E 。我有一个类似的需要,我需要一个虚拟主机内的虚拟路径。让我说,两个主机,我有。

I am using the WampServer version 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.

NameVirtualHost *:80

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

我的应用虚拟主机

<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>

我的博客虚拟主机

<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>

我的要求,现在是有 HTTP://apps.ptrl/blog/ HTTP://blog.praveen-kumar.ptrl / 应该是相同的目录。有一件事我想的是,移动博客应用程序文件夹里面文件夹,但它与<$ C连接$ C>的Git 和其他东西都在那里,所以它是不能移动的文件夹。

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 blog folder inside the apps folder, but it is connected with Git and other stuffs are there, so it is not possible to move the folder.

所以,我想创建一个别名虚拟主机是这样的:

So, I thought of creating an alias to the VirtualHost in this way:

<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>

但是,当我试图访问 HTTP://apps.ptrl/blog ,我收到一个错误403禁止

我做了正确的事情?如果你需要看的访问日志和错误日志,他们在这里:

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.

<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>


更新#2:另一个问题:

我能够访问该网站。物理链接现在正在工作。也就是说,我能打开 HTTP://apps.ptrl/blog/index.php 而不是 HTTP://apps.ptrl/blog /view-1.ptf ,它被翻译成 HTTP://apps.ptrl/blog/index.php页=视图和ID = 1 。任何解决方案?


Update #2: Another Issue:

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.php but not http://apps.ptrl/blog/view-1.ptf, which gets translated to http://apps.ptrl/blog/index.php?page=view&id=1. Any solutions?

推荐答案

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

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

<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>

请注意,那就是,URL路径(第一部分的别名)是即使在不区分大小写的文件系统区分大小写。

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

另外,从检查权限C:/ WAMP /虚拟主机/ ptrl /普利文 - 库马尔/博客目录

参考

  • Apache Module mod_alias
  • Apache Virtual Host

这篇关于在虚拟主机内创建一个别名目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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