Key facts
- The main file is usually /etc/nginx/nginx.conf, which includes site files from /etc/nginx/conf.d/*.conf or /etc/nginx/sites-enabled/.
- Directives end with a semicolon and are grouped in blocks such as http { }, server { } and location { }.
- Plain text, typically a few KB; there is no per-directory override like Apache's .htaccess.
- Changes only apply after a reload, and nginx -t checks the syntax of the whole configuration first.
- Written by sysadmins and generated by control panels, Certbot, Docker images and hosting platforms.
How to open a .conf file
Download it via SFTP (WinSCP or FileZilla) and edit it in VS Code or Notepad++, or connect with VS Code Remote-SSH to edit it on the server.
Edit the server copy over SSH with nano, or a local Homebrew install's config, which lives under /opt/homebrew/etc/nginx/ on Apple silicon.
Run sudo nano /etc/nginx/sites-available/example.conf, then sudo nginx -t to test and sudo systemctl reload nginx to apply.
Common problems and fixes
- "nginx: [emerg] unexpected "}"" or "directive is not terminated by ";""
- A semicolon or brace is missing on or just before the reported line. Fix it and run sudo nginx -t until it reports 'syntax is ok'.
- "nginx: [emerg] unknown directive"
- The directive is misspelled, belongs to a module that is not installed, or an Apache rule was pasted in. Check the spelling and the Nginx docs for the correct directive and context.
- 502 Bad Gateway
- Nginx cannot reach the upstream app or PHP-FPM. Check that the fastcgi_pass socket or proxy_pass address matches the running service and read /var/log/nginx/error.log.
- 413 Request Entity Too Large on uploads
- The default client_max_body_size is 1m. Raise it in the http, server or location block, for example client_max_body_size 64m;, and reload Nginx.
- Single-page app or WordPress URLs return 404 on refresh
- Nginx looks for a real file at the path. Add try_files $uri $uri/ /index.html; for SPAs or try_files $uri $uri/ /index.php?$args; for WordPress.
Often converted to or from: .htaccess, Apache VirtualHost config, Caddyfile