1

Is there a way to change the error log file name. Whatever I am doing, I always get the error logs written to the default file name "error.log" when a request gets processed. I have a global and only one error log configuration in main context:

user  npcache;
worker_processes  2;

error_log /opt/logs/nginx/error1.log notice;
pid       /opt/logs/nginx/nginx.pid;

events {
  worker_connections  1024;
  multi_accept on;
}

http {
  error_log  /opt/logs/nginx/error.log notice;
  include ./mime.types;
  default_type application/octet-stream;

  #Access log configuration
  log_format main '"$remote_addr" "$host" "$http_host" ["$time_local"]'
                  '"$request" $status $body_bytes_sent "$http_referer"';
  access_log /opt/logs/nginx/access.log main;
. . .
}

With this config I am getting error logs written to /opt/logs/nginx/error.log instead of "error1.log".

Am I missing something in the configuration?

I discovered that the issue was related to the second error log in http context that was eclipsing the top-level one.

Thanks

  • I am using nginx from: nginx version: openresty/1.9.3.1 – HK guess Jan 29 '16 at 17:31
  • Please post your whole nginx.conf and please format it! – uzsolt Jan 29 '16 at 18:14
1

You need to post something like this in your nginx.conf, which is probably in /etc/nginx/nginx.conf. It goes at the top of the file, outside the events and http blocks. You can also put it in at the server or location level. Documentation here.

error_log  /var/log/nginx/error.log warn;

Nginx documentation is excellent, and many queries have been answered on Server Fault and online already. Sometimes a search can save you time having to wait for people to answer your question.

| improve this answer | |
  • I discovered that the issue was related to the second error log in http context that was eclipsing the top-level one. Thanks for your answer. – HK guess Jan 29 '16 at 20:11
  • As you've probably discovered you can have error_log at multiple levels. You have have the error log named anything you want, stored anywhere you want. – Tim Jan 29 '16 at 23:45
-1

You apparently can not change the initial error log, it's set a compile time. This initial log is used to report errors in the config file etc. before accepting connections.

I understand the logic behind this, but I believe that's not a good choice. It means you have to have root access in order to make the /var/log/nginx/* log directory writable for normal users, if you want to run multiple NGINX in your system with different (non-root) users.

@nginx developers: I would suggest to send initial errors to STDERR, as the tradition says...

| improve this answer | |
  • Or you can simply test a new configuration before trying to restart nginx with it. – Michael Hampton Sep 7 '19 at 9:42
  • That's not the problem they were having. They answered their own question at some point at the end of their question "I discovered that the issue was related to the second error log in http context that was eclipsing the top-level one." – Tim Sep 7 '19 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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