在fedora 34, Laravel, SELinux中被禁止访问Apache (httpd) &



我已经在我的fedora中配置了httpd,我检查了一切都是真的,但我得到

禁止访问

我已经测试了所有关于。htaccess,但仍然得到访问禁止。此外,我的laravel文件夹权限是正确的。我在安装httpd时测试了一个示例项目,它完美地工作,没有"禁止访问"消息。


这是我的httpd配置

<VirtualHost *:80>
ServerName  test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

这是我的htaccess在laravel公共文件夹

<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

你可能是把旧的Apache语法和新的Apache语法混在一起造成了这个问题,Apache的现代版本应该是这样的…

<VirtualHost *:80>
ServerName  test.com
ServerAlias www.test.com
DocumentRoot /home/myuser/gitlab/register/public
<Directory /home/myuser/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>

我找到问题了。

这是因为

SELinux

ubuntu默认不使用SELinux,但RedHat发行版默认使用它。出于安全考虑,SELinux阻止apache访问主目录,因此如果禁用或将其设置为许可模式,apache可以访问您的主目录来加载web项目。如果你不想禁用SELinux所以web应用程序的正确位置是在/var/www/文件夹如果我们将HTTPD配置改为

<VirtualHost *:80>
ServerName  test.com
ServerAlias www.test.com
DocumentRoot /var/www/gitlab/register/public
<Directory /var/www/gitlab/register/public>
DirectoryIndex index.php
AllowOverride All
Require all granted
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

it works fine

最新更新