5

Here's my situation whenever I reboot:

$ systemctl --failed
UNIT          LOAD   ACTIVE SUB    DESCRIPTION
nginx.service loaded failed failed A high performance web server and a reverse proxy server
...
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2014/01/18 05:44:47 [emerg] 254#0: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
$ cd /run
$ ls -al | grep nginx
$ sudo systemctl start nginx
$ ls -al | grep nginx
-rw-r--r--  1 root     root        4 Jan 18 06:27 nginx.pid

I don't understand how nginx.pid could have incorrect permissions before it's even created, or what one would do to resolve that.

I'm using Arch and I've seen similar issues relating to chroot-jail, but I did not install nginx in a chroot.

Ryne Everett
  • 2,383
  • I would suggest that you ensure that there doesn't already exist a pid file with wrong owner or permission. I had a similar issue where I was running uwsgi in a python virtual env and pid file was not accessible because there was already a pid file existing with wrong permissions which someone had created earlier. – APZ Jan 18 '14 at 19:43
  • Thanks for taking a look. That was my first thought as well, which is why I cd'd to /run and greped for the file. As you can see above, the pid file isn't created until I manually start nginx. I tried changing the permissions, but they're reset after each reboot. – Ryne Everett Jan 18 '14 at 19:58
  • 1
    I am a Ubuntu user mainly and whenever I have start nginx or any service I use sudo . I see you doing nginx -t (not sure of the whole systemctl functioning) but it might be worth check as what user is nginx trying to start because pid is owned by root. – APZ Jan 18 '14 at 20:28

2 Answers2

8

The issue seems to be you are using an unprivileged user to test the Nginx configuration. When the test occurs, it attempts to create /run/nginx.pid, but fails and this causes the configuration test to fail. Try running nginx as root.

$ sudo nginx -t

or

$ su - -c "nginx -t"

This way, the Nginx parent process will have the same permission it would when run by systemctl.

If this resolves the error at testing, but not when run from systemctl, you may want to check this page on investigating systemd errors.

ir0h
  • 331
0

For me, I just changed the selinux from enforcing to permissive and then I was able to start nginx without any error.

  • I don't know much about selinux, but that sounds inadvisable. If you want to avoid typing sudo/password, I would give your user root access to things on an individual basis. http://unix.stackexchange.com/questions/18830/how-to-run-a-specific-program-as-root-without-a-password-prompt – Ryne Everett Mar 18 '15 at 04:33