Laravel和Lumen的Apache别名

时间:2015-04-27 16:00:54

标签: php apache laravel lumen

我尝试在我的服务器上创建一个别名,该别名会将example.com/z/中的所有流量指向与example.com其余部分不同的目录,其中example.com具有Laravel 4.2安装和example.com/z/具有运行服务的流明安装。

这是我原来的vhost:

<VirtualHost *:80>
 ServerName example.com
 DocumentRoot /data/user/public_html/public
 <Directory /data/user/public_html/public>
  Options +FollowSymlinks
  AllowOverride All
 </Directory>
</VirtualHost>

这是添加了/z/别名的虚拟主机:

 <VirtualHost *:80>
  ServerName example.com
  DocumentRoot /data/user/public_html/public
  Alias /z/ /data/user/service/public
  <Directory /data/user/service/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
  <Directory /data/user/public_html/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
 </VirtualHost>

导航到exmaple.com/z/时,我收到403页并在日志中显示此错误:

 Directory index forbidden by Options directive: /data/user/service/public

如果我转到/z/下的任何其他内容(示例:/z/abcd),我会得到一个404页面,但它看起来像是Laravel 404页面而不是Lumen 404页面。

关于如何让这个工作的任何想法?

2 个答案:

答案 0 :(得分:14)

该消息告诉您没有添加选项<Directory /data/user/service/public> Options +FollowSymlinks +Indexes AllowOverride All </Directory>

Alias /z /data/user/service/public

你的别名可能必须是

Alias /z/ /data/user/service/public/

import java.util.ArrayList;
import java.util.List;

public class Parsing {
    public static void main(String[] args) {
        String input = "aksdbaalaskdhfbblajdfhacccc aoudgalsaa bblisdfhcccc";
        System.out.println(input);

        for (int i = 0; i < input.length(); i++) {
            System.out.print(i/10);
        }
        System.out.println();

        for (int i = 0; i < input.length(); i++) {
            System.out.print(i%10);
        }
        System.out.println();

        List<String> tokenisedSearch = parseExp("a+b+c-");
        System.out.println(tokenisedSearch);

        parse(input, 0, tokenisedSearch, 0);
    }

    public static boolean parse(String input, int searchFromIndex, List<String> tokensToSeach, int currentTokenIndex) {
        if(currentTokenIndex >= tokensToSeach.size())
            return true;
        String token = tokensToSeach.get(currentTokenIndex);
        int found = input.indexOf(token, searchFromIndex);
        if(found >= 0) {
            System.out.println("Found at Index "+found+ " Token " +token);
            return parse(input, searchFromIndex+1, tokensToSeach, currentTokenIndex+1);
        }
        return false;
    }

    public static List<String> parseExp(String exp) {
        List<String> list = new ArrayList<String>();
        String runningToken = "";
        for (int i = 0; i < exp.length(); i++) {
            char at = exp.charAt(i);
            switch (at) { 
            case '+' :
                runningToken += runningToken;
                list.add(runningToken);
                runningToken = "";
                break;
            case '-' :
                runningToken += runningToken;
                runningToken += runningToken;
                list.add(runningToken);
                runningToken = "";
                break;
            default :
                runningToken += at;
            }
        }
        return list;
    }
}

答案 1 :(得分:1)

未经测试,但添加Require all granted应删除部分共享限制。

要考虑的另一件事是确保您的文件夹实际上归Apache的所有者所有(www-data,apache,甚至是您的用户名或其他东西,具体取决于您的安装)。如果Apache无法读取该文件夹,则会触发错误。

我还将目录切换为引用别名而不是文件路径。

 <VirtualHost *:80>
  ServerName example.com
  DocumentRoot /data/user/public_html/public
  Alias /z /data/user/service/public
  <Directory /z>
   Options +FollowSymlinks +Indexes
   AllowOverride All
   Require all granted
  </Directory>
  <Directory /data/user/public_html/public>
   Options +FollowSymlinks
   AllowOverride All
  </Directory>
 </VirtualHost>