Opened 2 years ago

Closed 2 years ago

#2307 closed defect (invalid)

Can not use variable in error_log filename

Reported by: JAM2199562@… Owned by:
Priority: minor Milestone:
Component: other Version: 1.19.x
Keywords: log Cc:
uname -a: 3.10.0-1160.49.1.el7.x86_64 #1 SMP Tue Nov 30 15:51:32 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.20.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.1.1g FIPS 21 Apr 2020 (running with OpenSSL 1.1.1k FIPS 25 Mar 2021)
TLS SNI support enabled
configure arguments: --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic' --with-ld-opt='-Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-E'

Description

When I configure nginx with the following settings, the filename of the error log is not as expected
What I'm expecting is

www.example.com-access.log
www.example.com-error.log

what i get is

www.example.com-access.log
$server_name-error.log

  server {
    server_name www.example.com;
    listen 8083;
    access_log /var/log/nginx/$server_name-access.log;
    error_log /var/log/nginx/$server_name-error.log;
    location / {
      proxy_pass http://10.10.10.10:50000/;
    }
  }
 


Change History (1)

comment:1 by Maxim Dounin, 2 years ago

Resolution: invalid
Status: newclosed

That's expected, the error_log directive does not support variables. Error logs are to be evaluated in case of errors, in particular, when memory allocation fails, hence there are no plans to introduce variables support.

Note that when variables supported by a directive parameter, this is explicitly documented, like in access_log: "The file path can contain variables (0.7.6+), but such logs have some constraints...".

Note well that using variables to shorten the configuration might not be a good idea, see FAQ. Consider using the server name explicitly, both in error_log (where variables are not supported and you have to) and in access_log (where variables are supported, but using the name explicitly will be much more effective in your use case).

Note: See TracTickets for help on using tickets.