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

**Code:** `nginx: [emerg] unexpected end of file, expecting ";" or "}"` · **Category:** Nginx / Apache · **Seen on:** Nginx, Linux

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-emerg-unexpected-end-of-file)
