GrepBoard/Manuals
605 manuals ·

Fix nginx directive has no opening "{"

·Tested on nginx 1.30.6 (Docker) · 2026-11·Test scope ↓·8 steps

nginx 'directive has no opening "{"' means a block directive such as location, if or upstream ended with ";" instead of "{". Fix the statement, test, reload.

output
2026/11/06 22:26:16 [emerg] 14#14: directive "location" has no opening "{" in /etc/nginx/nginx.conf:6nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:6nginx: configuration file /etc/nginx/nginx.conf test failed

The directive in quotes (location) must be followed by a block opened with {, but its statement ended with ;. Add { ... } to the statement that carries the name. The line number is the line holding the ; that ended the statement, not the line with location, so the example above points one line below it.

In the nginx source (ngx_conf_file.c, 1.30.6), a block directive that ends with anything other than { fails with this error before nginx counts its arguments. The opposite mistake, a { after a directive that takes no block, gives directive is not terminated by ";".

[1] Read the directive name and line number from the error.

console
# nginx -t

If the error is in an included file, the path points at that file. Here the first line of conf.d/api.conf was location /api;.

output
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/conf.d/api.conf:1

[2] Find the named directive and see where its statement ends. Below, the { was forgotten on location, so the statement ends at the ; on the next line and the error pointed at line 6.

/etc/nginx/nginx.conf
        location /api            return 204;

Keep a copy of the original first, then add the { together with its matching }.

/etc/nginx/nginx.conf
        location /api {            return 204;        }

[3] It is not only location; every block directive behaves the same. A one-line if is a common case.

/etc/nginx/nginx.conf
        if ($request_method = POST) return 405;
output
nginx: [emerg] directive "if" has no opening "{" in /etc/nginx/nginx.conf:5

Rewrite it as if ($request_method = POST) { return 405; }. An upstream backend inside http, with no { after the name and a server line following, also gave directive "upstream" has no opening "{".

[4] If the { is clearly there and the error stays, look for a # before it. Everything after # to the end of the line is a comment, so the { is not read at all.

/etc/nginx/nginx.conf
        location /api # {            return 204;        }
output
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:6

Move the { before the #. The nginx documentation says the rest of a line after the # sign is considered a comment.

[5] A { on the next line is not the cause. This configuration passed nginx -t.

/etc/nginx/nginx.conf
        location /api        {            return 204;        }
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

[6] A different message means the { is missing somewhere else. If the line right after location /api is }, you get unexpected "}"; if http is the last line of the file, you get unexpected end of file.

output
nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:6nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:2

For a missing closing }, see unexpected end of file, expecting "}".

[7] After the fix, test, and reload only if the test passes. nginx -t only checks the files, so the running nginx keeps the old configuration until you reload.

console
# nginx -t
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
console
# nginx -s reload; echo "reload exit=$?"
output
2026/11/06 22:26:18 [notice] 54#54: signal process startedreload exit=0

The nginx documentation says to send the HUP signal to the master process to make it re-read the configuration. The master checks the syntax first, and if applying fails it rolls back and keeps working with the old configuration.

[8] If you skip the test and reload a broken configuration, the running service did not stop on 1.30.6. /ping answered old; nginx was then reloaded with the { after location /ping removed.

console
# nginx -s reload; echo "reload exit=$?"
output
2026/11/06 22:26:17 [emerg] 48#48: directive "location" has no opening "{" in /etc/nginx/nginx.conf:8nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:8reload exit=1
console
# curl -s localhost:8080/ping
output
old
console
# grep -c SIGHUP /tmp/error.log
output
0

The command printed the error and exited with 1, and the error log (/tmp/error.log in this test) had no SIGHUP line. On this version nginx -s reload appears to read the configuration before it sends the signal. The control documentation does not say so, and it was not checked on other versions or through a service manager's reload, so keep running nginx -t first.

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

#nginx#nginx-t#location#brace#config