← Back to all fixes

nginx -t fails with cryptic emerg error

The Issue

`sudo nginx -t` shows: `nginx: [emerg] unknown directive "server_namee"` or similar.

Root Cause

Syntax error in the config file — typo in a directive name, missing semicolon, unclosed bracket, or a corrupt file from copy-paste.

How to Fix
  1. Read the exact error — it includes file path and line number
  2. Open the file: `sudo nano /etc/nginx/sites-available/mysite`
  3. Common errors: missing `;` at end of line, unclosed `{`, typo in directive name
  4. Validate with: `sudo nginx -t 2>&1` — piping stderr helps see full output
  5. Start from a minimal working config and add blocks one at a time to find the bad section