Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's my situation whenever I reboot:

$ systemctl --failed
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.

share|improve this question
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
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
up vote 5 down vote accepted

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


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

share|improve this answer

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

share|improve this answer
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. unix.stackexchange.com/questions/18830/… – Ryne Everett Mar 18 '15 at 4:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.