【问题标题】:i get access forbidden from Apache (httpd) in fedora 34, Laravel, SELinux我在 Fedora 34、Laravel、SELinux 中禁止从 Apache (httpd) 访问
【发布时间】:2021-11-04 22:45:11
【问题描述】:

我已经在我的 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>

这是我在 laravel 公用文件夹中的 htaccess

<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>

【问题讨论】:

  • 您尝试过什么来解决问题?这与 Fedora 或 Laravel 本身有什么关系?
  • 我在 ubuntu 上做同样的配置,它没有问题,但在 Fedora 中,我得到了`访问禁止`。在某些情况下,laravel 项目中的 .htaccess 可能会导致这样的问题我已经测试过有关 laravel .htaccess 的解决方案,我确信 laravel 项目及其文件夹权限并非如此
  • 那么肯定是有区别的。你试图找到什么?比如:错误日志是否包含任何消息?权限设置是否恰当?文件夹存在吗?
  • 是的,文件夹权限正确

标签: laravel .htaccess fedora httpd.conf selinux


【解决方案1】:

您可能通过混合旧的 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>

【讨论】:

  • 感谢我尝试过的帮助,但问题仍然存在@MikeMoy
【解决方案2】:

我发现了问题。

这是因为

SELinux

ubuntu 默认不使用 SELinux,但 RedHat 发行版默认使用它。 SELinux 为安全起见阻止 apache 访问主目录,因此如果您禁用或将其设置为 Permissive 模式,则 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>

效果很好

【讨论】:

  • 没有“Web 应用程序的正确位置”之类的东西,一旦配置正确,apache 可以从您选择的任何文件夹中为 Web 应用程序提供服务
猜你喜欢
  • 2016-11-11
  • 2017-10-13
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 2017-09-04
  • 2018-08-14
  • 2017-02-20
  • 2017-05-31
相关资源
最近更新 更多