Laravel 和 Lumen 的 Apache 别名
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29900607/
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
Apache alias for Laravel and Lumen
提问by Samsquanch
I'm trying to make an alias on my server which directs all traffic that comes into example.com/z/
to a different directory than the rest of example.com
, where example.com
has a Laravel 4.2 install and example.com/z/
has a Lumen install which runs a service.
我正在尝试在我的服务器上创建一个别名,它将所有流量引导到example.com/z/
与其余目录不同的目录中example.com
,其中example.com
安装了 Laravel 4.2 并example.com/z/
安装了运行服务的 Lumen。
This is my original vhost:
这是我原来的虚拟主机:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /data/user/public_html/public
<Directory /data/user/public_html/public>
Options +FollowSymlinks
AllowOverride All
</Directory>
</VirtualHost>
And this is the vhost with the /z/
alias added in:
这是/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>
When a navigate to exmaple.com/z/
I get a 403 page and in the logs this error:
当导航到exmaple.com/z/
我得到一个 403 页面并在日志中出现此错误时:
Directory index forbidden by Options directive: /data/user/service/public
And if I go to anything else under /z/
(example: /z/abcd
) I get a 404 page, but it looks like the Laravel 404 page instead of the Lumen 404 page.
如果我转到/z/
(example /z/abcd
:)下的任何其他内容,我会得到一个 404 页面,但它看起来像 Laravel 404 页面而不是 Lumen 404 页面。
Any ideas on how I can get this working?
关于如何让这个工作的任何想法?
回答by Antonio Carlos Ribeiro
The message is telling you didn't added the option Indexes
该消息告诉您没有添加该选项 Indexes
<Directory /data/user/service/public>
Options +FollowSymlinks +Indexes
AllowOverride All
</Directory>
Your alias probably will have to be
您的别名可能必须是
Alias /z /data/user/service/public
or
或者
Alias /z/ /data/user/service/public/
回答by bastien
Directory index forbidden by Options directive: /data/user/service/public
选项指令禁止的目录索引:/data/user/service/public
Apache has not found file specified by DirectoryIndex
- default to index.php
index.html
and cannot show indexes
follow you're configuration
Are you sure there is one of this files present in /data/user/service/public
?
Apache 未找到指定的文件DirectoryIndex
- 默认为index.php
index.html
并且无法显示indexes
按照您的配置 您确定 中存在此文件之一/data/user/service/public
吗?
Be sure of this and add and .htaccess
into you're public directory
确保这一点并添加.htaccess
到您的公共目录中
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
from http://lumen.laravel.com/docs/installation#pretty-urls
来自http://lumen.laravel.com/docs/installation#pretty-urls
or add a directory block to parent level (if there is some symb link)
或添加一个目录块到父级(如果有一些符号链接)
<Directory /data/user>
Options -Indexes FollowSymLinks
AllowOverride all
Order Allow,Deny
Allow from all
</Directory>
回答by smcjones
Untested, but adding Require all granted
should remove some of the sharing restrictions.
未经测试,但添加Require all granted
应该删除一些共享限制。
The other thing to consider is ensuring your folder is actually owned by Apache's owner (www-data, apache, or even your username or something else depending on your installation). If the folder can't be read by Apache, it will trigger an error.
要考虑的另一件事是确保您的文件夹实际上归 Apache 的所有者所有(www-data、apache,甚至您的用户名或其他内容,具体取决于您的安装)。如果 Apache 无法读取该文件夹,则会触发错误。
I also switched the Directory to refer to the Alias rather than the file path.
我还切换了目录以引用别名而不是文件路径。
<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>