[英]Apache Server: Editing httpd.conf file (permission denied)
所以我最近按照此处指示的说明下载了 Apache 服务器及其所有文件(httpd、apr、apr-util、pcre): http://httpd.apache.org/docs/2.4/install.html
但是,在设置之后,当我尝试启动位于我的 usr/local/bin/ 中的 Apache 服务器时,系统提示我这条消息:
[allen@allen-lnx ~]$ /usr/local/bin/apachectl start
(13)Permission denied: AH00091: httpd: could not open error log file /usr/local/logs/error_log.
AH00015: Unable to open logs
经过一些研究,我发现我需要编辑我的 httpd.conf 文件,我之前这样做是为了允许正确的 ServerName 和 Listen 选项。 但是,我不确定如何编辑我的 conf 文件以允许访问“日志”目录。
值得注意的是,该命令将在我使用“sudo”命令时运行,但我不希望总是使用它,因为它似乎是一种变通方法。
任何帮助将不胜感激。 谢谢!
编辑:我实际上注意到我可能有两个 httpd.conf 文件,事实证明这有点麻烦。 另一个位于我的根 /etc/ 目录 (etc/httpd/conf/httpd.conf)。 我想我现在修改后的问题是……我应该保留哪一个? /etc/ 版本是内置版本吗,正如下面 faff 的评论所指出的那样?
当前解决方案:我想我会接受这样一个事实,即在编辑此文件时我需要使用 sudo,因为我需要成为 root 用户。 我可能稍后会更改它,以便我始终以 root 身份运行,但现在, sudo
就足够了。
这看起来像是文件系统权限的问题。 确保/usr/local/logs/
目录存在且可由您运行Apache的用户编写。
如果您不希望普通用户可以将logs
目录写入,则可以创建日志文件:
sudo touch /usr/local/logs/error_log
然后将文件的所有者更改为正确的用户:
sudo chown allen /usr/local/logs/error_log
假设你想以用户allen
身份运行Apache。
如果要更改Apache日志文件的位置,请在httpd.conf文件中查找ErrorLog
指令(如果不存在,则必须添加它):
ErrorLog path/to/logfile
对于使用SELinux的每个人,如果您删除了文件夹或遇到类似问题,您可能需要做几件事。
使用ln -s /var/log/httpd /etc/httpd/logs
重新链接文件夹默认情况下,日志保存在var文件夹下,但在/ etc / httpd / logs文件夹中引用
使用chcon system_u:object_r:httpd_config_t:s0 /etc/httpd/logs
应用SELinux安全权限chcon system_u:object_r:httpd_config_t:s0 /etc/httpd/logs
当然,以管理员身份运行一切
将SELinux安全策略更改为允许修复我的问题。
在修复之前,我的SELinux使用强制模式:
$ sestatus -v
sestatus -v
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 30
我在SELinux配置文件和系统中更改了安全策略。
#/etc/selinux/config
SELINUX=permissive
# In terminal set SELinux to run in permissive mode.
$ setenforce 0
修复后,我的SELinux使用强制模式:
$ sestatus -v
SELinux status: enabled
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 30
对于那些坚持使用 SElinux 策略的人,我可以通过创建自定义策略来做到这一点
基本上我想将/var/log/httpd
移动到/r/
下我自己的目录
所以我运行以下
semanage fcontext -a -t httpd_sys_content_t "/r/www(/.*)?"
semanage fcontext -a -t httpd_log_t "/r/logs(/.*)?"
restorecon -Rv /z/logs/
restorecon -Rv /z/www/
service httpd restart
# worked
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.