OPTIONS指令禁止使用服务器生成的目录索引 [英] Apache - Server-generated directory index forbidden by Options directive
本文介绍了OPTIONS指令禁止使用服务器生成的目录索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在CentOS7、Apache和LAMP中部署了我的Laravel应用程序。创建了两个子域并映射了目录,如下所示
子域
- abc.example.com->;/var/www/abc.example.com/public_html/public
- xyz.example.com->;/var/www/xyz.example.com/public_html/public
虚拟主机配置
为每个子域创建了虚拟主机配置文件。例如,对于abc.example.com,在/etc/conf.d/abc.example.com.conf中创建了文件和具有以下条目的/var/www/abc.example.com/public_html/.htaccess中。
public_html/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect All Requests To The Subfolder
RewriteRule ^ /public
和具有以下条目的/var/www/abc.example.com/public_html/public/.htaccess中。
public_html/public/.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
另外,index.php(/abc.example.com/public_html/index.php)包含laravel的默认代码,如下所示
数据-lang="js"数据-隐藏="假"数据-控制台="真"数据-巴贝尔="假"><?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylor@laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'/vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(IlluminateContractsHttpKernel::class);
$response = $kernel->handle(
$request = IlluminateHttpRequest::capture()
);
$response->send();
$kernel->terminate($request, $response);
浏览http://abc.example.com时显示禁止错误
另外,error.log文件记录以下异常。
AH01276: Cannot serve directory /var/www/abc.example.com/public_html/public/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive
推荐答案
您需要授权包含代码的目录 您可以尝试此命令:
sudo chown -R www-data:www-data /var/www/abc.example.com/public_html/
sudo find /var/www/abc.example.com/public_html/ -type f -exec chmod 644 {} ;
sudo find /var/www/abc.example.com/public_html/ -type d -exec chmod 755 {} ;
sudo chgrp -R www-data /var/www/abc.example.com/public_html/storage/
这篇关于OPTIONS指令禁止使用服务器生成的目录索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文