GrepBoard/Manuals
605 manuals ·

Fix nginx block directives are not supported in -g option

·Tested on nginx 1.28.0 (Docker) · 2026-11·Test scope ↓·4 steps

Move blocks such as events out of the nginx -g argument and into the right context in nginx.conf, then verify the corrected command with nginx -t.

output
2026/11/21 23:15:48 [emerg] 1#1: block directives are not supported in -g option in command linenginx: [emerg] block directives are not supported in -g option in command linenginx: configuration file /test/nginx.conf test failed

For block directives are not supported in -g option, remove the block from the nginx -g argument and put it in the right context in the configuration file. Version 1.28.0 parses the -g string before the file. The diagnostic's in command line points to that string. The last line names the file selected for the test. nginx 1.28.0 initialization code · Configuration parser

[1] Find -g in the actual invocation. If you ran nginx in a shell, check the failed command. If a service ran it, check the service definition. For a systemd unit named nginx.service, check the pre-start test, startup, and reload commands. For a container, check the command in the deployment definition and the arguments the entrypoint passes to nginx.

console
$ systemctl show -p ExecStartPre -p ExecStart -p ExecReload nginx.service

Read the entire quoted -g value. In 'daemon off; events {}', move the events {} part. Simple directives passed with -g end with a semicolon. The parser raises this error when it encounters the opening { of a block while processing -g. Changing the shell quotes has the same result if nginx receives the same string. nginx command-line options

[2] Move the block to its proper context in the file. Put events and http at the top level. If an events block already exists, merge the needed directives into it. Put server inside http, and put an HTTP location inside the relevant server. Save copies of the current launcher definition and configuration file before editing either.

The complete test file follows. In production, keep the existing blocks and apply only the needed changes. nginx configuration file structure

run/nginx.conf
events {    worker_connections 128;} http {}

[3] Test the same file with and without the block in -g. The official image read the file above at /test/nginx.conf. This first command produced the diagnostic at the top and returned exit code 1.

console
$ nginx -t -c /test/nginx.conf -g 'events {}'

Drop -g 'events {}' because the file already contains the block. The second command reads the same file and returned exit code 0.

console
$ nginx -t -c /test/nginx.conf
output
nginx: the configuration file /test/nginx.conf syntax is oknginx: configuration file /test/nginx.conf test is successful

Keep daemon off; if the existing invocation requires it. The same file also passed with this simple directive.

console
$ nginx -t -c /test/nginx.conf -g 'daemon off;'
output
nginx: the configuration file /test/nginx.conf syntax is oknginx: configuration file /test/nginx.conf test is successful

[4] Test with the production arguments before applying the change. Use the production binary, its -c and -p options, and any remaining -g value. If you changed how a service or container launches nginx, apply the change through the deployment path that starts it with the new arguments. A configuration reload leaves the running process's startup arguments in place. If rollout fails, restore the saved launcher definition and configuration, test the last working setup, and roll it back through your deployment procedure.

If there is a file and line number and the error says directive "location" has no opening "{", check the opening brace in the file. For is not terminated by ";", check where the simple directive ends.

Analyze your Nginx log in the browser ↗ — nothing is uploaded.

#nginx#nginx-t#nginx-g#nginx-conf#events