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.
server {
listen 80
server_name example.com;
}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.
location /api/ {
proxy_pass http://127.0.0.1:3000
}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.
gzip on;
gzip_types text/css application/jsongzip 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.
location / {
return 200 "ok;
}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.