1

I have a ~/nginx.conf with error_log /home/user/error.log (also in http section), and it works smoothly with sudo nginx -c ~/nginx.conf.

But without sudo I get [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied), though nginx seems to work.

What is the cause and how to get rid of it?

UPD: used config

worker_processes 4;
pid /home/user/nginx.pid;

error_log /home/user/error.log;

events {
  worker_connections 768;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  access_log /home/user/access.log;
  error_log /home/user/httperror.log;

  server {
    listen 8080 default_server;

    root /home/user/static;
    index index.html;

    server_name localhost;

    location / {
      try_files $uri $uri/ =404;
    }
  }
}
tim zh
  • 93
  • 6
  • 2
    That simply means you have no access rights to access the log file. Run `ls -l /var/log/nginx/error.log` to see who is the owner of that file and what are permission. You can change permission with `sudo chmod` and ownership with `sudo chown`. Permissions of the directory holding that file are also important – vrs Jan 10 '16 at 11:07
  • We can't answer without seeing your config. – Sobrique Jan 10 '16 at 11:21
  • @vrs, I understand that, but I don't know why nginx accesses default error.log, though it was changed in config – tim zh Jan 10 '16 at 11:28
  • @timzh update you quiestion with the entire config, please – vrs Jan 10 '16 at 11:30
  • Does `nginx -c ~/nginx.conf -g "error_log /home/user/error.log;"` help? – Oleg Jan 10 '16 at 13:42
  • 1
    BTW, this might help: http://stackoverflow.com/questions/13371925/how-to-turn-off-or-specify-the-nginx-error-log-location – Oleg Jan 10 '16 at 13:44
  • @Curious, no; thanks for the link, now it at least makes sense – tim zh Jan 10 '16 at 17:11

0 Answers0