Laravel 文档根被禁止并出现 HTTP 403 错误
Laravel document root Forbidden with HTTP 403 error
我已经 laravel 安装了 CentOS 7 服务器。 PHP,MariaDB 和 HTTPD 已安装并正常工作。所有服务都已启动并运行。浏览文档根目录显示
Forbidden
You don't have permission to access / on this server.
这是我服务器的文档根目录
DocumentRoot "/var/www/html/api/public"
文档根配置
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
这是 welcome.conf 文件 ( /etc/httpd/conf.d/welcome.conf)
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
我能为这个问题做什么?
创建此 .htaccess 文件并将其放入您的应用程序文件夹。
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
以下服务器配置已解决我的问题。
授予文件夹权限并设置所有权
chown -R apache:apache /var/www/html/laravel
chmod -R 755 /var/www/html/laravel/storage
恢复安全
restorecon -R /var/www
禁用 SELinux
setenforce 0
我已经 laravel 安装了 CentOS 7 服务器。 PHP,MariaDB 和 HTTPD 已安装并正常工作。所有服务都已启动并运行。浏览文档根目录显示
Forbidden
You don't have permission to access / on this server.
这是我服务器的文档根目录
DocumentRoot "/var/www/html/api/public"
文档根配置
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
这是 welcome.conf 文件 ( /etc/httpd/conf.d/welcome.conf)
# This configuration file enables the default "Welcome" page if there
# is no default index page present for the root URL. To disable the
# Welcome page, comment out all the lines below.
#
# NOTE: if this file is removed, it will be restored on upgrades.
#
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html
Alias /noindex/css/bootstrap.min.css /usr/share/httpd/noindex/css/bootstrap.min.css
Alias /noindex/css/open-sans.css /usr/share/httpd/noindex/css/open-sans.css
Alias /images/apache_pb.gif /usr/share/httpd/noindex/images/apache_pb.gif
Alias /images/poweredby.png /usr/share/httpd/noindex/images/poweredby.png
我能为这个问题做什么?
创建此 .htaccess 文件并将其放入您的应用程序文件夹。
RewriteEngine on RewriteCond %{REQUEST_URI} !^public RewriteRule ^(.*)$ public/ [L]
以下服务器配置已解决我的问题。
授予文件夹权限并设置所有权
chown -R apache:apache /var/www/html/laravel
chmod -R 755 /var/www/html/laravel/storage
恢复安全
restorecon -R /var/www
禁用 SELinux
setenforce 0