虚拟主机文档路由之外的Apache别名

时间:2012-12-27 01:13:15

标签: apache alias

我的情况是我的图像与文档根目录处于同一级别。

所以我需要/ Users / jwindhall / Sites / gdw / my_app / images(www.example.local / images)

指向/ Users / jwindhall / Sites / gdw / images。

我一直在做:

其余的......

<VirtualHost *:80>
ServerAdmin example@whatever.com
DocumentRoot "/Users/jwindhall/Sites/gdw/my_app/"
ServerName www.example.local
ServerAlias www.example.local
<Directory "/Users/jwindhall/Sites/gdw/my_app">
   Options All Includes Indexes FollowSymLinks
   Order allow,deny
   Allow from all
   AllowOverride All
</Directory>
Alias /images /Users/jwindhall/Sites/gdw/images
</VirtualHost>

我做错了什么?

2 个答案:

答案 0 :(得分:2)

需要在虚拟主机中定义Alias(或直接在服务器配置中定义,但这可能不是一个好主意):

<VirtualHost *:80>
    ServerAdmin example@whatever.com
    DocumentRoot "/Users/jwindhall/Sites/gdw/my_app/"
    ServerName www.example.local
    ServerAlias www.example.local
    <Directory "/Users/jwindhall/Sites/gdw/my_app">
        Options All Includes Indexes FollowSymLinks
        Order allow,deny
        Allow from all
        AllowOverride All
    </Directory>

    Alias /images /Users/jwindhall/Sites/gdw/images
    <Directory "/Users/jwindhall/Sites/gdw/images">
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

答案 1 :(得分:1)

将Alias放在VirtualHost中。此外,您不需要与ServerName相同的ServerAlias。

 <VirtualHost *:80>
    ServerAdmin example@whatever.com
    DocumentRoot "/Users/jwindhall/Sites/gdw/my_app/"
    ServerName www.example.local
    <Directory "/Users/jwindhall/Sites/gdw/my_app">
       Options All Includes Indexes FollowSymLinks
       Order allow,deny
       Allow from all
       AllowOverride All
    </Directory>
    Alias /images /Users/jwindhall/Sites/gdw/images
 </VirtualHost>

如果这不起作用,你会得到什么错误? apache用户是否可以访问images目录?