Fedora 23 上新安装的 Apache 出现 500 错误。一个文件加载,另一个没有加载

Fedora 23 上新安装的 Apache 出现 500 错误。一个文件加载,另一个没有加载

好吧,我发现这有点奇怪。

因此,我使用 Apache 的大部分经验都是在 Ubuntu 服务器安装上获得的。但在我的服务器硬盘发生灾难性故障后(幸运的是,我恢复了所有数据),我抓住机会切换到最新的 Fedora 服务器。这有几个原因,但最大的原因是 Ubuntu 服务器安装程序存在问题,具体来说,它无法识别我的无线键盘,而我上一个有线键盘坏了。

无论如何,我安装了 httpd(apache)、php、postgresql 和 php-pgsql。然后我将所有旧网站页面移至新的 Web 目录 (/var/www/html/)。然后我收到 500 错误。

我决定从头开始,玩个痛快。将我的网页移到一边(移到 /var/www/html2/),然后创建一个小页面进行测试。只是基本的 HTML,没有什么花哨的,没有 PHP,只是基础知识。

<html>
<head>
<title>HOME!!!</title>
</head>
<body>
<h1>THIS WORKS!!!</h1>
</body>
</html>

加载没有任何问题。

然后我将每个页面移回主文件夹(目前除了 .htaccess),我刚刚创建的页面仍然运行良好。我怀疑问题出在 php 上,于是在底部添加了一些 php 代码:

echo 'hello';

工作得很好。

事情开始变得奇怪了。我尝试将我网站上的旧 footer.php 包含到这个小测试页面中,问题就从这里开始。页脚根本无法加载。

<?php include 'footer.php'; ?>

页面的其余部分可以加载,只是页脚加载不了。然后,出于好玩,我将页脚文件的所有内容复制到一个名为 footer2.php 的新文件中,并将测试页面改为引用 footer2.php,结果加载起来完全没有问题。

所以我终于觉得我找到了一些方法,所以我将 footer.php 的权限更改为与 footer2.php 一致。但它仍然无法加载。

由于某种原因,footer.php 无法加载,但 footer2.php 可以加载。

那么差别是什么?

这些文件完全相同!以下是证据:

[blackwidower@Twilight html]$ md5sum footer*
257cbd773ed765deb5ad0015852cdf20  footer2.php
257cbd773ed765deb5ad0015852cdf20  footer.php
[blackwidower@Twilight html]$ ls -l footer*
-rw-rw-r--. 1 blackwidower blackwidower 1271 Feb  1 00:08 footer2.php
-rw-rw-r--. 1 blackwidower blackwidower 1271 Feb  1 00:08 footer.php

但其中一个可以加载,另一个却不能。

我可以做些什么来找到可以分离这些文件的更多数据?

作为参考,这里是 apache error_log:

[Mon Feb 01 00:14:15.160242 2016] [core:notice] [pid 1800] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:s0
[Mon Feb 01 00:14:15.161310 2016] [suexec:notice] [pid 1800] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.7.2. Set the 'ServerName' directive globally to suppress this message
[Mon Feb 01 00:14:15.192180 2016] [auth_digest:notice] [pid 1800] AH01757: generating secret for digest authentication ...
[Mon Feb 01 00:14:15.192361 2016] [http2:warn] [pid 1800] AH02951: mod_ssl does not seem to be enabled
[Mon Feb 01 00:14:15.193015 2016] [lbmethod_heartbeat:notice] [pid 1800] AH02282: No slotmem from mod_heartmonitor
[Mon Feb 01 00:14:15.218713 2016] [mpm_prefork:notice] [pid 1800] AH00163: Apache/2.4.18 (Fedora) PHP/5.6.17 configured -- resuming normal operations
[Mon Feb 01 00:14:15.218762 2016] [core:notice] [pid 1800] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
[Mon Feb 01 00:14:43.969957 2016] [:error] [pid 1801] [client 192.168.7.7:49878] PHP Fatal error:  Call to undefined function displayCopyrightInfo() in /var/www/html/footer2.php on line 13
[Mon Feb 01 00:14:44.086110 2016] [core:error] [pid 1802] (13)Permission denied: [client 192.168.7.7:49880] AH00035: access to /images/cc-by-nc-nd-88x31.png denied (filesystem path '/var/www/html/images/cc-by-nc-nd-88x31.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:14:44.087064 2016] [core:error] [pid 1804] (13)Permission denied: [client 192.168.7.7:49882] AH00035: access to /images/valid-xhtml10-blue.png denied (filesystem path '/var/www/html/images/valid-xhtml10-blue.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:14:44.087737 2016] [core:error] [pid 1806] (13)Permission denied: [client 192.168.7.7:49884] AH00035: access to /images/vcss-blue.png denied (filesystem path '/var/www/html/images/vcss-blue.png') because search permissions are missing on a component of the path, referer: http://192.168.7.2/index2.php
[Mon Feb 01 00:15:47.538488 2016] [:error] [pid 1808] [client 192.168.7.7:49890] PHP Warning:  include(footer.php): failed to open stream: Permission denied in /var/www/html/index2.php on line 7
[Mon Feb 01 00:15:47.538534 2016] [:error] [pid 1808] [client 192.168.7.7:49890] PHP Warning:  include(): Failed opening 'footer.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/index2.php on line 7

编辑:

根据某人的建议,我运行了 ls -Z。以下是我发现的内容:

unconfined_u:object_r:httpd_sys_content_t:s0 /var/www/html/footer2.php
               system_u:object_r:fusefs_t:s0 /var/www/html/footer.php

所以我找到了一个微分方程。问题是:这是什么意思,如何纠正它?

答案1

所以我找到了一个微分方程。问题是:这是什么意思,如何纠正它?

扩展用户 @Dirk 的注释,SELinux 是一个依赖“上下文”来提高系统安全性的系统,上下文描述了可以对某个文件或目录执行哪些操作,或者文件可以用于什么。在本例中,footer2.php具有上下文httpd_sys_content_t,因此这意味着该文件可以用于“http 目的",您需要做的是添加相同的上下文标签,footer.php以便可以通过 SELinux 安全系统访问它,或者只是在父目录上恢复上下文(在大多数系统上,默认情况下,位置中的文件/var/www设置为 " 的标签http 目的“)。另一种方法是完全禁用 SELinux,但这不是一个好的做法。

所以,

要(永久地)在文件上设置上下文标签footer.php

semanage fcontext -a -t httpd_sys_content_t /var/www/html/footer.php
restorecon /var/www/html/footer.php

您可以对父目录(及其所有内容)执行相同操作:

semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
restorecon -R "/var/www/html(/.*)?"

您可以在以下位置找到更多信息针对安全增强型 Linux 的 Red Hat 客户门户

相关内容