php Linux debian服务器上的Laravel VPS:您没有权限访问此资源

o2gm4chl  于 5个月前  发布在  PHP
关注(0)|答案(3)|浏览(71)

我在VPS服务器Linux Debian上部署了一个Laravel应用程序。但是我在我的网页上收到一条消息,比如:
禁止
您没有权限访问该页面!
我尝试了许多配置,特别是我的laravel.conf位于/etc/apache2/sites-enabled/和我的.htaccess位于我的项目根级别。
我也试过命令bellow:

sudo find /var/www/html/laravel_app -type d -exec chmod 644 {} \;
sudo find /var/www/html/laravel_app/storage -type f -exec chmod 755 {} \;

字符串
我已经花了一个星期的时间来做这个问题,我试了很多其他的stackoverflow的答案都没有成功。
这里是我的laravel.conf文件

<VirtualHost *:80 *:3000>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/laravel_app
    <Directory /var/www/html/laravel_app>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


下面是我的.htaccess文件

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

    RewriteEngine On
    DirectoryIndex index.php

    # 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}]
</IfModule>

myzjeezk

myzjeezk1#

您的DocumentRoot/var/www/html/laravel_app,但Laravel的index.php位于名为public的目录中。
看起来你的DocumentRoot指向你的Laravel根目录,但那里没有index.php。如果你没有启用+Indexes的目录列表.
更新你的根目录指向Laravel的public目录:

<VirtualHost *:80 *:3000>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/laravel_app/public
    <Directory /var/www/html/laravel_app/public>
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>
    LogLevel debug
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

字符串

    • 备注**

您提到"* my. htaccess located in my project root level *"-如果您的意思是您已经将.htaccesslaravel_app/public/.htaccess移动到laravel_app/.htaccess,请不要这样做。As the docs say
您不应该尝试将index.php文件移动到项目的根目录下,因为从项目根目录为应用程序提供服务会将许多敏感的配置文件暴露给公共Internet:

    • 注2**

你在Apache配置中混合了旧指令和新指令。来自文档:

    • 新旧指令混合**

将Order、Allow或Deny等旧指令与Require等新指令混合在一起在技术上是可行的,但不鼓励这样做。
这是Apache 2.2配置,应该删除:

Order allow,deny
Allow from all


这被Apache 2.4的配置等价物所取代,你已经正确地拥有了:

Require all granted

    • 注3**

正如我在评论中提到的,如果你有多个vhost,你应该是using ServerName,这样Apache就可以为传入的请求确定使用哪个主机配置。如果你只有这一个Laravel vhost,禁用所有其他的。

xdnvmnnf

xdnvmnnf2#

试试这个结构:

<VirtualHost *:80>
     ServerAdmin admin@site
     ServerName laravel_app
     ServerAlias www.laravel_app.com
     DocumentRoot /var/www/laravel_app/public
     DirectoryIndex index.php

     <Directory /var/www/laravel_app/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
     Require all granted
     </Directory>
     ErrorLog ${APACHE_LOG_DIR}/laravel_app_error.log
     CustomLog ${APACHE_LOG_DIR}/laravel_app_access.log combined
</VirtualHost>

字符串
正如在注解中所说的,你应该添加public目录,因为它包含了要呈现的index.php文件. wish,它可以帮助你解决你的问题。

esyap4oy

esyap4oy3#

最后,我发现了导致权限访问错误的问题。在我的/etc/apache2/sites-enabled目录中,我已经有另一个名为default-ssl.conf的vhost配置文件。由于未知原因,这是我的服务器执行的这个文件,而不是我创建并启用sudo a2ensite laravel.conf的vhost文件。所以我编辑了该文件并使用@不要惊慌回答配置.另一个问题是有关我的.htaccess你提到.我移动.htaccess并将其放在laravel_app/public目录.我不得不执行下面的这些命令也授予权限:

sudo find /var/www/html/laravel_app -type d -exec chmod 755 -R {} \;
sudo find /var/www/html/laravel_app -type f -exec chmod 644 -R {} \;

字符串
在我的.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}]


在我的default-ssl.conf下面

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerAdmin [email protected]
    DocumentRoot /var/www/html/laravel_app/public
    
    <Directory /var/www/html/laravel_app/public>
        DirectoryIndex index.php    
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLEngine on

    SSLCertificateFile  /etc/ssl/certs/ssl-cert-snakeoil.pem
    SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key

    <FilesMatch "\.(cgi|shtml|phtml|php)$">
            SSLOptions +StdEnvVars
    </FilesMatch>
    <Directory /usr/lib/cgi-bin>
            SSLOptions +StdEnvVars
    </Directory>

</VirtualHost>


现在它工作正常。但我有一个像不安全的连接在这个网站上的消息。我会在另一个讨论或文档中寻找。我认为SSL配置问题。谢谢大家,真的很感激和对不起我的英语!

相关问题