5

I'm running nginx using common user not root. I have nginx installed system-wide, but have nginx.conf in HOME.

$HOME/nginx/nginx.conf

worker_processes  1;
error_log  /home/worker/nginx/log/nginx/error.log warn;
pid        /home/worker/nginx/run/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include      /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log   /home/worker/nginx/log/nginx/access.log;
  server {
    listen 8080;
    root /home/worker/nginx/data;
  }
}

start nginx

$ nginx -c /home/worker/nginx/nginx.conf
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

As you can see in the nginx.conf, I have defined error_log, but I still got the warning message:

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

nginx itself works, just want to remove this warning message, how can I do that?

5
  • Hmm. I misread this at first. I suspect somebody else did too. Are you sure that is your entire nginx configuration? May 14, 2019 at 4:04
  • @MichaelHampton Sorry for my bad English. Thank you for your time, yes. this is the minimal conf file that can produce the issue.
    – gacopu
    May 14, 2019 at 4:09
  • Have you tried: nginx -q -c /home/worker/nginx/nginx.conf? May 14, 2019 at 6:33
  • @RichardSmith Just tried, no change.
    – gacopu
    May 14, 2019 at 6:52
  • Add sudo before nginx... command $ sudo nginx ...
    – Joe
    Oct 13, 2023 at 15:38

4 Answers 4

5

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

2
  • basically a link-only answer. I'm curious how to send errors to stderr Aug 16, 2023 at 19:59
  • @DevinRhode this flag is documented now. You have to use nginx -e stderr Feb 2 at 6:25
5

I'm late to the party, but I've had this issue for another reason. I simply added the access rights to the folder and files for nginx (www-data user in my case):

sudo chown -R www-data:www-data /var/log/nginx

I've actually removed the whole folder and log file and recreated them:

sudo rm -rf /var/log/nginx
sudo mkdir /var/log/nginx
sudo touch /var/log/nginx/error.log
sudo chown -R www-data:www-data /var/log/nginx

Maybe there is a more elegant solution.

3

This error is shown because the user executing nginx does not have permission to view the log file created by the ngnix process, which is most likely owned by www-data and not the user. Running the command with sudo, if possible, or giving the user permissions on the error log will eliminate the error message being shown.

3
  • Yes this helped me. I was using : $ nginx -t nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2022/06/18 16:23:43 [warn] 5039#5039: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 2022/06/18 16:23:43 [emerg] 5039#5039: open() "/run/nginx.pid" failed (13: Permission denied) nginx: configuration file /etc/nginx/nginx.conf test failed but then I used:$ sudo nginx -t ..conf syntax is ok Jun 18, 2022 at 21:32
  • Running a web service with superuser power exposes your app to external threads. Please do not do that, is a very bad habit. Regards. Oct 9, 2022 at 18:03
  • sudo nginx -t and errors are elimated. nginx syntax ok and test successful.
    – b_dubb
    Oct 18, 2023 at 18:22
1

There doesn't seem to be a way to eliminate this "alert".

See same question in StackOverflow: https://stackoverflow.com/questions/34258894/nginx-still-try-to-open-default-error-log-file-even-though-i-set-nginx-config-fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .