
Always validate configuration with
nginx -t after editing. That single step catches most syntax and placement errors before you try to reload or restart NGINX.1) Always validate configuration: nginx -t
Runnginx -t every time you edit any configuration file. It checks syntax and reports errors with file and line references so you can fix problems before reloading.
Example session showing a successful test, then editing a site and encountering a missing semicolon error:
http { ... }) inside a server block. That produces an error like:
nginx -t output carefully — it tells you the file and approximate line number where parsing failed.
2) Use reload instead of restart when possible
A reload applies configuration changes gracefully without dropping active connections (in most cases). Prefer:systemctl restart nginx when a reload cannot resolve the issue (for example, after upgrading the nginx binary). Restarting will briefly drop connections and may create a visible outage for connected users.
Prefer
nginx -s reload or systemctl reload nginx to avoid dropping active connections. Use restart only when necessary (e.g., after a binary upgrade).3) Global configuration and logging
The main/etc/nginx/nginx.conf holds global settings such as worker_processes, logging defaults, gzip and SSL settings. Avoid making broad global changes unless you understand their performance and compatibility implications.
A common global section:
4) Per-site logs: create directories and set permissions
When you configure per-site log paths, NGINX will create the log files but not the parent directories. If a parent directory is missing,nginx -t or startup will fail with an error indicating it couldn’t open the log file.
Example site server block (corrected):
/var/log/nginx/example.com/ does not exist, nginx -t will report an error similar to:
5) Quick service checks with curl
When users report an outage, usecurl locally on the server to determine whether NGINX is responding or if the issue is DNS/firewall/external:
Example: check local HTTP redirect (NGINX responding with 301):
curl will show a connection failure:
curl from the server works but external clients cannot connect, investigate DNS records and firewall/security group rules.
You can force local resolution using /etc/hosts when DNS isn’t pointing to the server yet. Example entries:
6) Firewalls and cloud security groups
Check both the host firewall and any cloud-level firewalls (security groups, network ACLs). Exampleufw status:
80 and 443 are open. Even if you redirect HTTP to HTTPS, keeping 80 open helps certificate challenges (Let’s Encrypt) and users who type http://.
If your infrastructure is in a cloud provider (AWS, GCP, Azure), verify that security groups / firewall rules allow the same ports.
Quick reference: common checks and commands
Final tips (cheat-sheet)
- Always run
nginx -tafter editing configuration files and before reloading. - Use
nginx -s reloadorsystemctl reload nginxfor config changes to avoid dropping active connections. - Make minimal global configuration changes unless you understand performance and compatibility trade-offs.
- Create per-site log directories and set proper ownership so NGINX can write logs.
- Test from the server with
curlto distinguish NGINX problems from DNS or network/firewall issues. - When troubleshooting, follow the path: syntax → service state → local request → firewall/cloud network → DNS → clients.
Links and references
- NGINX Documentation — Beginner’s Guide
- systemd.service — systemctl reload/restart reference
- curl — Manual
- UFW — Uncomplicated Firewall documentation