如果在 systemctl status nginx 命令中出现了权限错误,应该如何处理?

事件

将Nginx安装到CentOS 7上,并从其他地方复制配置文件。
在执行systemctl start nginx的时候

[root@localhost ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 火 2016-03-08 14:09:21 JST; 11min ago
  Process: 3012 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)

 3月 08 14:09:21 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
 3月 08 14:09:21 localhost.localdomain nginx[3012]: nginx: [emerg] open() "/etc/nginx/addtional.conf" failed (13: Permission denied) in /etc/nginx/nginx.conf:52
 3月 08 14:09:21 localhost.localdomain nginx[3012]: nginx: configuration file /etc/nginx/nginx.conf test failed
 3月 08 14:09:21 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
 3月 08 14:09:21 localhost.localdomain systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
 3月 08 14:09:21 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
 3月 08 14:09:21 localhost.localdomain systemd[1]: nginx.service failed.

有时会发生。
如果不在该服务器上创建配置文件,而是从其他服务器复制过来,很容易发生。

对应内容

参考kakiro-web的CentOS7.1 64位SELinux访问控制方法来实施。

chcon -t httpd_config_t /etc/nginx -R
ls -lZ /etc/nginx/addtional.conf

如果复制的内容只是文件,那么只需指定文件即可,使用文件路径 chcon /etc/nginx/addtional.conf;但如果是整个目录,就需要指定目录路径 chcon /etc/nginx/addtional.conf。

广告
将在 10 秒后关闭
bannerAds