SELinux的“https_log_t策略”不生效

我试图在运行Fedora 26服务器的Digital Ocean Droplet上使用apache httpd来设置虚拟主机。 我遵循这个教程: 如何在CentOS 7上设置Apache虚拟主机 ,假设Fedora和CentOS有相似之处。 我已经按照教程来设置这个虚拟主机,如下所示:

 <VirtualHost *:80> ServerName www.mywebsite1.com ServerAlias mywebsite1.com DocumentRoot /var/www/html/mywebsite1.com/public_html ErrorLog /var/www/html/mywebsite1.com/log/error_log CustomLog /var/www/html/mywebsite1.com/log/requests_log combined </VirtualHost> 

但是,设置后,我得到httpd无法启动。 事实certificate,这是造成这个错误,因为我追溯到httpd错误日志:

 (13)Permission denied: AH00091: httpd: could not open error log file /var/www/html/mywebsite1.com/log/error_log. AH00015: Unable to open logs 

那么,我查找了解决scheme,发现这可能是由于SELinux政策。 使用ls -lZ /var/www/html/mywebsite1.com ,打印出当前策略如下:

 total 8 drwxr-xr-x. 2 apache apache unconfined_u:object_r:httpd_sys_content_t:s0 4096 Oct 1 09:54 log drwxr-xr-x. 2 apache apache unconfined_u:object_r:httpd_sys_content_t:s0 4096 Oct 1 09:14 public_html 

我遵循了为Apache Web服务器configurationSELinux策略,并尝试将httpd_log_t策略添加到./log文件夹,并使用以下命令:

 $ semanage fcontext -a -t httpd_log_t "/var/www/html/mywebsite1.com/log(/.*)?" $ restorecon -Rv /var/www/html/mywebsite1.com 

但是, log文件夹仍然没有应用httpd_log_t策略,并且httpd仍然无法启动,并具有与以前相同的错误。 我甚至试图用httpd_sys_rw_content_t设置public_html文件夹,并没有工作。

我认为政策的制定过程可能有些问题。 但我找不到任何工作解决scheme。 在这个过程中有什么我错过的吗? 真的很感谢你的帮助!

我认为你需要一个特定types的执法。

  1. 首先检查/var/log/audit/audit.log特定的拒绝错误消息。 你可以运行这个:

sealert -a /var/log/audit/audit.log

  1. 然后针对特定的错误消息运行grep,并通过audit2allowpipe道。

grep myerror /var/log/audit/audit.log|audit2allow -v

这将输出您需要的特定types执行。

我发现问题是在vhostconfiguration中指定两个日志文件没有创build, 似乎httpd没有力量来创build它

所以我

  • /var/www/html/mywebsite1.com/log/创build了一个空的error_logrequests_log
  • 重新执行$ semanage ...$ restorecon ...命令,以获得正确的输出:

 Relabeled /var/www/html/mywebsite1.com/log from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:httpd_log_t:s0 Relabeled /var/www/html/mywebsite1.com/log/error_log from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:httpd_log_t:s0 Relabeled /var/www/html/mywebsite1.com/log/requests_log from unconfined_u:object_r:httpd_sys_content_t:s0 to unconfined_u:object_r:httpd_log_t:s0 

httpd重启之后,这一切都奏效了! 该网站回到可访问,这些日志文件现在保持日志。