大网数据广告活动
服务器运维问答

'https_log_t policy' of SELinux is not taken into effect

· 52CE 我爱测

I was trying to set up a virtual host using apache httpd on a Digital Ocean Droplet running Fedora 26 Server. And I followed this tutorial: How to Set Up Apache Virtual Hosts on CentOS 7 , assuming the similarities between Fedora…

问题原文

原帖链接 · jackxujh · CC BY-SA 3.0

I was trying to set up a virtual host using apache httpd on a Digital Ocean Droplet running Fedora 26 Server. And I followed this tutorial: How to Set Up Apache Virtual Hosts on CentOS 7, assuming the similarities between Fedora and CentOS. I have followed the tutorial to set up this virtual host as follows:

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

However, after the set up, I got httpd unable to start. It turned out that it was caused this error, as I traced to the httpd error log:

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

So then, I looked up for solutions and found that it may due to the SELinux policies. Using ls -lZ /var/www/html/mywebsite1.com, the current polices is printed out as follows:

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

I followed Configuring SELinux Policies for Apache Web Servers and tried to add httpd_log_t policy to ./log folder, and used these:

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

$ restorecon -Rv /var/www/html/mywebsite1.com

However, the log folder still does not have httpd_log_t policy applied and httpd still cannot start, with the same error as before. I even tried to set the public_html folder with httpd_sys_rw_content_t, and it didn't work.

I think there may be something wrong with the setting process of policies. But I couldn't find any working solutions to this. Is there anything I missed along the process? Really appreciate your help!

已采纳解答

原帖链接 · jackxujh · CC BY-SA 3.0

I found out the issue was that the two log files specified in the vhost configuration was not created, and it seems that httpd does not have the power to create it somehow.

So I

  • created an empty error_log and requests_log in /var/www/html/mywebsite1.com/log/,
  • re-did the $ semanage ... and $ restorecon ... commands, to get the correct output:

.

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

And after a httpd restart, it all worked! The site is back to accessible, and those log files are keeping logs now.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-10-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。