用systemctl启动nginx会失败,但手动运行命令不会

在Arch Linux上,出于某种原因,当我尝试用命令“systemctl start nginx”启动nginx时,它失败了,这是“systemctl status nginx”的输出:

Loaded: loaded (/etc/systemd/system/nginx.service; enabled) Active: failed (Result: exit-code) since Wed 2013-10-30 16:22:17 EDT; 5s ago Process: 9835 ExecStop=/usr/bin/chroot --userspec=http:http /home/nginx /usr/bin/nginx -g pid /run/nginx.pid; -s quit (code=exited, status=126) Process: 3982 ExecStart=/usr/bin/chroot --userspec=http:http /home/nginx /usr/bin/nginx -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=0/SUCCESS) Process: 10967 ExecStartPre=/usr/bin/chroot --userspec=http:http /home/nginx /usr/bin/nginx -t -q -g pid /run/nginx.pid; daemon on; master_process on; (code=exited, status=126) Main PID: 3984 (code=exited, status=0/SUCCESS) CGroup: /system.slice/nginx.service 

…但是当我跑步

 /usr/bin/chroot --userspec=http:http /home/nginx /usr/bin/nginx -t -q -g "pid /run/nginx.pid; daemon on; master_process on;" 

接着

 /usr/bin/chroot --userspec=http:http /home/nginx /usr/bin/nginx -g "pid /run/nginx.pid; daemon on; master_process on;" 

作为根,它所做的只是返回一个警告,但工作得很好:

 nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 

为什么这样做?

编辑:在看了/var/log/messages.log后,我发现这个:

 /usr/bin/chroot: failed to run command '/usr/bin/nginx': Permission denied 

但是ls -l / home / nginx / usr / bin / nginx会返回:

 -rwxr-xr-x 1 root root 797040 Oct 25 18:24 nginx 

..和所有导致/ home / nginx / usr / bin /的目录是chmodded a + x

我遇到了同样的问题,这是由于SELinux

要检查SELinux是否正在运行:

 # getenforce 

要在下一次重新启动之前禁用SELinux:

 # setenforce Permissive 

重新启动Nginx,看看问题是否存在。 如果您想永久更改设置,您可以编辑/etc/sysconfig/selinux

如果SELinux是你的问题,你可以运行以下命令让nginx能够为你的www目录服务(确保你在testing之前重新打开SELinux,例如setenforce Enforcing

 # chcon -Rt httpd_sys_content_t /path/to/www 

如果仍有问题,请查看getsebool -a中的布尔标志,特别是可能需要打开httpd_can_network_connect才能访问networking

 # setsebool -P httpd_can_network_connect on 

对我来说,足以让http服务我的www目录。