Skip to main content
And welcome to the final demo.
A simple slide showing the word "Troubleshooting" on the left and a large turquoise curved shape on the right labeled "Demo." The bottom-left corner shows "© Copyright KodeKloud."
Thanks for your patience. This write-up collects practical, prioritized troubleshooting tips for NGINX — what to check first, how to identify the root cause quickly, and common fixes.
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

Run nginx -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:
Another common mistake is placing a top-level directive (for example, http { ... }) inside a server block. That produces an error like:
Read the 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:
or on systemd-managed systems:
Only use 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:
If you change TLS protocol support (for example, restricting to TLS 1.2 and 1.3), do so intentionally — older clients might be unable to connect:

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):
If /var/log/nginx/example.com/ does not exist, nginx -t will report an error similar to:
Fix by creating the directory and setting ownership:
Then re-run:
Verify logs are being written:

5) Quick service checks with curl

When users report an outage, use curl 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):
Check HTTPS for the public site:
If you stop NGINX, curl will show a connection failure:
If 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). Example ufw status:
Ensure ports 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 -t after editing configuration files and before reloading.
  • Use nginx -s reload or systemctl reload nginx for 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 curl to distinguish NGINX problems from DNS or network/firewall issues.
  • When troubleshooting, follow the path: syntax → service state → local request → firewall/cloud network → DNS → clients.
Thanks for reading — I appreciate it.

Watch Video