How to turn off or specify the nginx error log location?

后端 未结 6 1322
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-01 11:09

I compiled the nginx on Ubuntu myself. I start my nginx with -c nginx.conf parameter. In my nginx.conf file, I try to turn off error log with but failed.

err         


        
相关标签:
6条回答
  • 2021-01-01 11:39

    I just solved this by using this configure parameter:

    ./configure --prefix="$HOME/nginx" --error-log-path=/dev/stderr
    

    Since I never use this nginx as a daemon and always run it in a shell, it makes sense for it to log errors to stderr.

    0 讨论(0)
  • 2021-01-01 11:43

    The syntax for disabling the error log is ok, but the docs state that a default logfile is used before the config is read. (which seems reasonable because how would it otherwise tell you you have an error in your config)

    Try creating this file by hand with the correct permissions for the user that runs nginx. Or try starting the server as root.

    0 讨论(0)
  • 2021-01-01 11:48

    I solved this issue using the -p parameter when starting nginx e.g:

    /home/ubuntu/nginx/sbin/nginx -c /home/ubuntu/nginx/conf/nginx.conf -p /home/ubuntu/nginx
    

    This will prepend any log paths specified in the config with the prefix directory.

    0 讨论(0)
  • 2021-01-01 11:48

    You can't solve the problem by specifying a -p prefix; because that would only apply to the directives in the configuration file; and as RickyA already noted the problem is that there is a compiled-in error log that nginx wants to open even before it opens the configuration. Changing permissions of the compiled-in error log is not ideal, for obvious reasons.

    A workaround is to specify the error log as a configuration on the command line:

    $ nginx -p . -g 'error_log error.log;'
    

    or

    $ nginx -p . -g 'error_log stderr;'
    

    You'll still get an [alert] but at least it allowed me to start nginx as non-root on Ubuntu.

    0 讨论(0)
  • 2021-01-01 11:53

    Per this post on the nginx.org mailing list (extract quoted below), the %%ERROR_LOG_PATH%% is set as a compile option, and checked immediately on startup, causing the "Could not open" alert. Specifying the prefix (with -p) may help suppress the alert, but only if the %%ERROR_LOG_PATH%% was specified as a relative path at compile time.

    You can check how it is specified in your current executable with

    nginx -V 2>&1 | grep -oE 'error-log-path=\S*'

    That is why the solution proposed by @Michael works for some, but not for others.

    See changelog:

    Changes with nginx 0.7.53

    ...

    *) Change: now a log set by --error-log-path is created from the very start-up.

    *) Feature: now the start up errors and warnings are outputted to an error_log and stderr.

    ...

    Now compiled in error_log value always used to log errors at start time (and emits warning if nginx can't open it). Once config file have been read - error_log from config will be used instead.

    If you have compiled nginx with error_log path relative to prefix - it should be possible to override startup error_log via -p switch.

    Maxim Dounin

    0 讨论(0)
  • 2021-01-01 12:00

    There's no need to use a command line parameter. Simply ensure you add the error_log directive to the very top of nginx.conf or at least before any error messages may occur.

    nh2's comment from Jan 2016 suggests that this option would have been available for at least a couple years now. I can confirm it works and it's less hassle. Customisation to nginx.conf is less likely to cause issues with updates to a packaged nginx installation than the alternatives.

    0 讨论(0)
提交回复
热议问题