nginx: [emerg] missing semicolon in the configuration

Every simple nginx directive ends with a semicolon; only block directives such as server { } and location { } do not. Without the semicolon, nginx reads the next line as extra arguments of the same directive, so the error you see depends on what follows: an “invalid parameter” when the next directive name is taken as an argument, “unexpected }” before a closing brace, or “unexpected end of file” at the end. PasteKit reports the directive that is missing its semicolon.

Seen as:

  • nginx: [emerg] invalid parameter "server_name" in /etc/nginx/conf.d/app.conf:3
  • nginx: [emerg] unexpected "}" in /etc/nginx/conf.d/app.conf:7
  • nginx: [emerg] directive "gzip_types" is not terminated by ";" in /etc/nginx/conf.d/gzip.conf:2
  • nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:41
  • nginx: configuration file /etc/nginx/nginx.conf test failed

Input

Settings

History

Load from URL

Common causes

1. A directive followed by another directive

Here nginx reads listen 80 server_name example.com; as one directive and rejects server_name as a parameter of listen. The line number points at the second line, but the missing semicolon is on the first.

Before
server {
    listen 80
    server_name example.com;
}
After
server {
    listen 80;
    server_name example.com;
}

2. The last directive before a closing brace

Without a semicolon, the directive runs into the }, which nginx reports as unexpected. The semicolon is required even on the last line of a block.

Before
location /api/ {
    proxy_pass http://127.0.0.1:3000
}
After
location /api/ {
    proxy_pass http://127.0.0.1:3000;
}

3. The last line of an included file

A snippet file pulled in with include must be complete on its own. If its final directive lacks a semicolon, nginx reports that the directive “is not terminated by ;” at the end of that file.

Before
gzip on;
gzip_types text/css application/json
After
gzip on;
gzip_types text/css application/json;

4. An unclosed quote hiding the semicolon

A missing closing quote turns the semicolon and everything after it into part of the string, so nginx later complains about the end of the file. Close the quote.

Before
location / {
    return 200 "ok;
}
After
location / {
    return 200 "ok";
}

Frequently asked questions

Do block directives need a semicolon after the closing brace?

No. server, location, http, events, upstream, if and map blocks end with } and no semicolon. Only simple directives, those without a block, need one.

How do I test my config before reloading?

Run nginx -t (or nginx -T to also print the merged config). It reports the first error with the file and line, and leaves the running server untouched.

Why does the error line point at the wrong directive?

nginx only notices the problem when the merged directive becomes invalid, which is on the next line or at the next brace. Look at the line above the reported one first.

Related