Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#2425 closed defect (duplicate)

Nginx failed validate config from stdin

Reported by: Hubbitus@… Owned by:
Priority: minor Milestone:
Component: documentation Version: 1.22.x
Keywords: Cc: Hubbitus@…
uname -a: Linux hubbitus.gid.note 6.0.11-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Dec 2 20:38:11 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.22.1
built with OpenSSL 3.0.5 5 Jul 2022
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-openssl-opt=enable-ktls --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-cc-opt='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' --with-ld-opt='-Wl,-z,relro -Wl,--as-needed -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -Wl,--build-id=sha1 -Wl,-dT,/builddir/build/BUILD/nginx-1.22.1/.package_note-nginx-1.22.1-1.fc36.x86_64.ld -Wl,-E'

Description

Hello.

Prior version 1.18 next config validation was worked:

nginx -t -c /dev/stdin <<< "events {worker_connections 1;} http { include /some/config.conf; }"

That had been used for ansible config validation, please refer to [this atackoverflow answer](https://serverfault.com/questions/674092/validate-nginx-conf-during-ansible-deploy/811520#811520).

For now that behaves very strange:

$ sudo nginx -T -c /dev/stdin <<< "events { worker_connections 2; } http { include /home/pasha/temp/nginx.validate/some.conf; }"
nginx: the configuration file /dev/stdin syntax is ok
nginx: [emerg] no "events" section in configuration
nginx: configuration file /dev/stdin test failed

As you see, events block is here!

$ cat /dev/stdin <<< "events { worker_connections 2; } http { include /home/pasha/temp/nginx.validate/some.conf; }"
events { worker_connections 2; } http { include /home/pasha/temp/nginx.validate/some.conf; }

Meantime, that worked with regular file:

$ bash -c 'echo "events { worker_connections 2; } http { include /home/pasha/temp/nginx.validate/some.conf; }" > /tmp/nginx.conf; sudo nginx -t -c /tmp/nginx.conf; rm -f /tmp/nginx.conf'
nginx: the configuration file /tmp/nginx.conf syntax is ok
nginx: configuration file /tmp/nginx.conf test is successful

Change History (2)

comment:1 by Maxim Dounin, 2 years ago

Resolution: duplicate
Status: newclosed

This never worked, including in nginx prior to 1.18.x, but might appear to work if your shell used to provide here-documents in temporary files. See #2381 for details.

comment:2 by Hubbitus@…, 2 years ago

Maxim, thank you for the answer and link.

Last edited 2 years ago by Hubbitus@… (previous) (diff)
Note: See TracTickets for help on using tickets.