Laravel - Forbidden 您无权访问 / 在此服务器上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18272557/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:35:54  来源:igfitidea点击:

Laravel - Forbidden You don't have permission to access / on this server

laravellaravel-4

提问by panthro

My laravel installation was working fine yesterday but today I get the following error:

昨天我的 Laravel 安装工作正常,但今天我收到以下错误:

Forbidden

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

Does anyone know where I am going wrong?

有谁知道我哪里出错了?

回答by Alexey

Create and put this .htaccess file in your laravel installation(root) folder.

创建并把这个 .htaccess 文件放在你的 Laravel 安装(根)文件夹中。

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^public
    RewriteRule ^(.*)$ public/ [L]
</IfModule>

回答by Hieu Tran AGI

I met the same issue, then I do same as the solution of @lubat and my project work well. :D My virtualhost configuration:

我遇到了同样的问题,然后我和@lubat 的解决方案一样,我的项目运行良好。:D 我的虚拟主机配置:

<VirtualHost *:80>
     ServerName laravelht.vn
     DocumentRoot D:/Lavarel/HTPortal/public
     SetEnv APPLICATION_ENV "development"
     <Directory D:/Lavarel/HTPortal/public>
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
         Order allow,deny
         Allow from all
     </Directory>
 </VirtualHost>

回答by Mohammad Shoriful Islam Ronju

Have you tried to change the .htaccess file that laravel suggested if the default one doesn't work? I had this similar problem and changed it to

如果默认文件不起作用,您是否尝试更改 laravel 建议的 .htaccess 文件?我遇到了类似的问题并将其更改为

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

and it soleved :)

它解决了:)

回答by lubart

Check your virtual host configuration. For Ubuntu you could find it at /etc/apache2/sites-available/yourlaravel.conf It should be like this:

检查您的虚拟主机配置。对于 Ubuntu,你可以在 /etc/apache2/sites-available/youurlaravel.conf 找到它应该是这样的:

<VirtualHost *:80>
ServerName yourlaravel.com
DocumentRoot "/path/to/your/laravel/project/public"
ServerAlias *.yourlaravel.com

<Directory "/path/to/your/laravel/project/public">
    AllowOverride All
    Require all granted
</Directory>

The key line is Require all grantedinside <Directory>.

关键线在Require all granted里面<Directory>

Hope it helps!

希望能帮助到你!

回答by star18bit

For those who using Mamp or Mamp pro:

对于那些使用 Mamp 或 Mamp pro 的人:

Open MAMP Pro
Click on “Hosts”
Click on “Extended” (UPDATE: Only if you are using MAMP Pro 3.0.6)
Check “Indexes”
Click “Save”
That's it! Reload your localhost starting page and it should work properly.

回答by PieterVK

With me the problem appeared to be about the fact that there was no index.php file in the public_html folder. When I typed in this address however: http://azxcvfj.org/public, it worked (this address is just an example. It points to nowhere). This made me think and eventually I solved it by doing the following.

对我来说,问题似乎与 public_html 文件夹中没有 index.php 文件有关。然而,当我输入这个地址时:http://azxcvfj.org/public,它起作用了(这个地址只是一个例子。它指向无处)。这让我思考并最终通过执行以下操作解决了它。

I made a .htaccess file in the app's root folder (the public_html folder) with this contents:

我在应用程序的根文件夹(public_html 文件夹)中创建了一个 .htaccess 文件,内容如下:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ / [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]
</IfModule>

And this worked. With this file you are basically saying to the server (Apache) that whenever someone is trying to access the public html folder(http://azxcvfj.org) that someone who is being redirected is redirected to http://azxcvfj.org/public/index.php

这奏效了。使用此文件,您基本上是在对服务器(Apache)说,每当有人尝试访问公共 html 文件夹(http://azxcvfj.org)时,被重定向的人将被重定向到http://azxcvfj.org/公共/index.php

回答by Ali

For me, It was just because I had a folder in my public_htmlnamed as same as that route!
so please check if you don't have a folder with the address of that route!
hope be helpful

对我来说,这只是因为我的public_html 中有一个与该路由名称相同的文件夹!
所以请检查您是否没有包含该路线地址的文件夹!
希望有帮助

回答by Ioannis Chrysochos

In your VirtualHost write the DocumentRoot to point to your Laravel Application in your home directories. In addition you must add the Directory shown below, with your own path:

在您的 VirtualHost 中写入 DocumentRoot 以指向您主目录中的 Laravel 应用程序。此外,您必须使用自己的路径添加如下所示的目录:

<Directory /home/john/Laravel_Projects/links/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
    Require all granted
</Directory>

The second step, you must go to your Laravel Project and run the following command.

第二步,你必须转到你的 Laravel 项目并运行以下命令。

sudo chmod -R 777 storage bootstrap/cache

At the end restart your apache2:

最后重启你的 apache2:

sudo service apache2 restart

回答by Evhz

It was solved for me with the Laravel default public/.htaccess fileadding an extra line:

使用Laravel 默认 public/.htaccess 文件添加了一行额外的行为我解决了这个问题:

The /public/.htaccessfile remains as follows:

/public/.htaccess文件保持如下:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On
    DirectoryIndex index.php # This line does the trick

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [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}]
</IfModule>

回答by Radames E. Hernandez

Just add a .htaccessfile in your root project path with the following code to redirect to the public folder:

只需.htaccess使用以下代码在根项目路径中添加一个文件即可重定向到公共文件夹:

.HTACCESS

.HTACCESS

## Redirect to public folder
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^$ public/ [L]
    RewriteRule (.*) public/ [L]
</IfModule>

Very simple but work for me in my server.

非常简单,但在我的服务器中对我来说有效。

Regards!

问候!