nginx: [emerg] unexpected end of file, expecting ";" or "}" Nginx / Apache Origin: Edge & web server OSI layer 7 · Application Last updated 5 Nov 2026

Nginx: nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/site.conf:42

The config ends while a block or directive is still open — a missing } or ;.

Exact message you may see nginx: [emerg] unexpected end of file, expecting ";" or "}"[emerg] unexpected end of file, expecting ";" or "}" in /etc/nginxnginx: [emerg] unexpected "}" in /etc/nginx/nginx.confnginx: configuration file /etc/nginx/nginx.conf test failed[emerg] unexpected end of parameter, expecting ";"
Seen on: Nginx Linux

Meaning

The line number points at the end of the file, but the mistake is earlier: an unclosed server {/location { or a directive lacking ;. Run nginx -t, then check brace balance (grep -c '{' file; grep -c '}' file) and view the file with an editor that highlights brackets.

Common causes

  • Missing closing brace }
  • Missing ; after a directive
  • Unbalanced braces after a copy-paste
  • Included snippet missing its closing brace
  • Stray character from an editor

⚡ Quick fix

  1. sudo nginx -t to get file and line
  2. Balance braces; add the missing ; or }
  3. Use an editor with bracket matching; validate each included file

Detailed fix by platform

Linux

  1. sudo nginx -t && sudo systemctl reload nginx; count braces: grep -o '{' site.conf | wc -l; grep -o '}' site.conf | wc -l

How to diagnose

  1. Line — File end?
  2. Braces — Balanced?
  3. Include — Which file?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):

AH00526: Syntax error on line of apache config — Apache: AH00526: Syntax error on line 12 of /etc/apache2/sites-enabled/site.conf: Invalid command 'Foo', perhaps misspelled or defined by a module not included in the server configuration (Nginx / Apache)AH00526: Syntax error…could not build the server_names_hash, you should increase server_names_hash_bucket_size — Nginx: nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 64 (Nginx / Apache)could not build the s…nginx: [emerg] open() failed (2: No such file or directory) — Nginx: nginx: [emerg] open() "/etc/nginx/snippets/fastcgi-php.conf" failed (2: No such file or directory) in /etc/nginx/sites-enabled/app:20 (Nginx / Apache)nginx: [emerg] open()…nginx: [emerg] unknown directive — Nginx: nginx: [emerg] unknown directive "x" in /etc/nginx/sites-enabled/x:12 — configuration file test failed (Nginx / Apache)nginx: [emerg] unknow…nginx: conflicting server name ignored — Nginx: nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored (Nginx / Apache)nginx: conflicting se…nginx: directive is not terminated by ";" — Nginx: nginx: [emerg] directive "proxy_pass" is not terminated by ";" in /etc/nginx/sites-enabled/app:15 (Nginx / Apache)nginx: directive is n…nginx: duplicate location — Nginx: nginx: [emerg] duplicate location "/" in /etc/nginx/sites-enabled/default:52 (Nginx / Apache)nginx: duplicate loca…nginx: invalid PID number in nginx.pid — Nginx: nginx: [error] invalid PID number "" in "/run/nginx.pid" (when running nginx -s reload) (Nginx / Apache)nginx: invalid PID nu…nginx: [e…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.