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

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

问题描述

我检查了 给出的说明更改了 VirtualHosts 声明:

服务器名称应用程序.ptrlDocumentRoot "C:/Wamp/vhosts/ptrl/apps"错误日志日志/应用程序-ptrl-error.log"CustomLog "logs/apps-ptrl-access.log" 常见# 博客的别名!别名/blog "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"<目录C:/Wamp/vhosts/ptrl/praveen-kumar/blog">允许所有人命令允许,拒绝允许覆盖所有</目录><目录C:/Wamp/vhosts/ptrl/apps">允许所有人命令允许,拒绝允许覆盖所有</目录>DirectoryIndex index.html index.htm index.php</虚拟主机>

<小时>

更新 #2:另一个问题:

我可以访问该网站.物理链接现在正在工作.即,我可以打开 http://apps.ptrl/blog/index.php 但不能打开 http://apps.ptrl/blog/view-1.ptf,它被翻译成 http://apps.ptrl/blog/index.php?page=view&id=1.有什么解决办法吗?

解决方案

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

服务器名称应用程序.ptrlDocumentRoot "C:/Wamp/vhosts/ptrl/apps"错误日志日志/应用程序-ptrl-error.log"CustomLog "logs/apps-ptrl-access.log" 常见# 放在这里,在目录指令之前:)别名/blog "C:/Wamp/vhosts/ptrl/praveen-kumar/blog"<目录C:/Wamp/vhosts/ptrl/apps">允许所有人命令允许,拒绝允许覆盖所有</目录></虚拟主机>

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

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

参考

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

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.

Primary Virtual Host (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 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>

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

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:

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

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?

解决方案

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>

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

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

Reference

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

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