Nginx still try to open default error log file even though I set nginx config file while reloading Nginx still try to open default error log file even though I set nginx config file while reloading nginx nginx

Nginx still try to open default error log file even though I set nginx config file while reloading


This is old... but I went through the same pain and here is my solution.

As you can see the log is an alert, not a blocking error:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

It shouldn't be a problem :) Nginx just likes to check that file on startup...

Just use -p option. Something like this to launch Nginx locally works for me:

nginx -c /etc/nginx/nginx.conf -g 'daemon off;' -p /home/Foo/log/nginx


You might need to fire it with sudo

sudo nginx -t


The alert comes from the nginx initialization procedure, when it checks that it can write to the error log path that has been compiled in with the --error-log-path configure flag. This happens before nginx even looks at your configuration file, so it doesn't matter what you write in it.

Recently (2020-11-19), an -e option was added to nginx, allowing you to override the error log path that has been compiled in. You can use that option to point nginx to a user-writeable file (or maybe stderr).

See https://trac.nginx.org/nginx/changeset/f18db38a9826a9239feea43c95515bac4e343c59/nginx