解决全新 Laravel 11 安装中的 403 Forbidden 错误

问题描述 投票:0回答:1

我在 CentOS 上使用 Nginx 和 Aapanel 控制面板。我在我的服务器上安装了最新的 Laravel 11,但是当我尝试访问它时,遇到 403 禁止错误。

我尝试了对 .htaccess 文件进行各种修改,但没有成功。我在网上进行了大量搜索,但尚未找到任何有用的资源。

我的URL重写配置如下:

location / {
  try_files $uri $uri/ /index.html index.php;
}
php laravel nginx laravel-11
1个回答
0
投票

有两件事似乎帮助我解决了同样的问题:

  1. 确保您服务器上的 php 版本与您的 Composer 文件中所述的版本相同。对我来说,我的作曲家文件需要 php 8.2,但我的服务器配置为 php 8.1。

  2. 我在根文件夹中创建了一个新的index.php文件,其中包含以下内容:

    
    /**
     * Laravel - A PHP Framework For Web Artisans
     *
     * @package  Laravel
     * @author   Taylor Otwell <[email protected]>
     */
    
    $uri = urldecode(
        parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
    );
    
    // This file allows us to emulate Apache's "mod_rewrite" functionality from the
    // built-in PHP web server. This provides a convenient way to test a Laravel
    // application without having installed a "real" web server software here.
    if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) {
        return false;
    }
    require_once __DIR__.'/public/index.php';```
    
    

我不知道 Laravel 11 在根文件夹中没有索引文件是否有充分的理由,但添加一个似乎对我有用。我希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.