Opened 4 years ago

Closed 4 years ago

#2011 closed defect (duplicate)

confusing stderr message 'could not open error log file: open() "/var/log/nginx/error.log"' even if not using default error_log location

Reported by: dan.streetman.canonical.com@… Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.19.x
Keywords: Cc:
uname -a: Linux test-nginx-g 5.4.0-37-generic #41-Ubuntu SMP Wed Jun 3 18:57:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.17.10 (Ubuntu)
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-Pmk9_C/nginx-1.17.10=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

Description

In src/core/nginx.c, in ngx_cdecl(), the commandline parameters are first checked by calling nginx_get_options(), but then ngx_log_init() is called before actually processing the cmdline options later on, by calling ngx_process_options().

This means the ngx_log_init() will always run with the default compile-time error_log location. This is easily reproducable by creating a simple custom config file like:

error_log error_log.txt;
worker_processes 1;                                                                                                                                                                                                                                                           
pid nginx.pid;                                                                                                                                                                                                                                                                

events {
  worker_connections 10;
}                                                                                                                                                                                                                                                                             
http {                                                                                                                                                                                                                                                                        
 default_type text/plain;                                                                                                                                                                                                                                                     
 server {                                                                                                                                                                                                                                                                     
  listen 127.0.0.1:8880;
  access_log access.log;                                                                                                                                                                                                                                                      
 }                                                                                                                                                                                                                                                                            
}                                                                                                                                                                                                                                                                             

then run that as any user that does not have write access to the default error log file:

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

Note that the configured error log file does get created and seems to be used, but the error message is still printed to stderr.

Change History (2)

comment:1 by dan.streetman.canonical.com@…, 4 years ago

Ah this is probably the same as https://trac.nginx.org/nginx/ticket/147

comment:2 by Maxim Dounin, 4 years ago

Resolution: duplicate
Status: newclosed

Yes, this is clearly a duplicate of #147.

Note: See TracTickets for help on using tickets.