Fix nginx directive has no opening "{"
nginx 'directive has no opening "{"' means a block directive such as location, if or upstream ended with ";" instead of "{". Fix the statement, test, reload.
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 failedThe 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.
# nginx -tIf 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;.
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.
location /api return 204;Keep a copy of the original first, then add the { together with its matching }.
location /api { return 204; }[3] It is not only location; every block directive behaves the same. A one-line if is a common case.
if ($request_method = POST) return 405;nginx: [emerg] directive "if" has no opening "{" in /etc/nginx/nginx.conf:5Rewrite 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.
location /api # { return 204; }nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:6Move 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.
location /api { return 204; }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.
nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:6nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:2For 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.
# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful# nginx -s reload; echo "reload exit=$?"2026/11/06 22:26:18 [notice] 54#54: signal process startedreload exit=0The 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.
# nginx -s reload; echo "reload exit=$?"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# curl -s localhost:8080/pingold# grep -c SIGHUP /tmp/error.log0The 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.