Skip to main content
And welcome to the final demo.
A clean presentation slide showing the word "Troubleshooting" on the left and a large turquoise shape on the right labeled "Demo." A small "© Copyright KodeKloud" appears in the bottom-left.
This guide collects practical troubleshooting steps for NGINX: quick checks, common configuration mistakes, and safe commands to apply changes in production. Follow the sequence below to diagnose most NGINX issues quickly and safely.

Quick checks (first steps)

  • Is the NGINX process running? sudo systemctl status nginx
  • Has configuration syntax changed? nginx -t
  • Are the expected ports open (80/443) locally and externally?
  • Are site logs present and owned by the web user?
Use the checklist at the end to confirm you didn’t miss any step.

Always test configuration first: nginx -t

Run nginx -t after editing configuration. It validates syntax and reports errors so you don’t break the running service on reload. Example: missing semicolon leads to an error
Common causes of nginx -t failures:
  • Syntax errors (missing ; or mismatched braces).
  • Directives placed in the wrong context (see next section).
  • Missing files referenced by the config (certificates, include files).

Context errors: directives must be in the right block

Some directives are only valid in specific contexts (main, http, server, location). Putting an http { ... } block inside a server block will fail. Example error when a directive is not allowed in this context
Correct usage: http is a top-level context in /etc/nginx/nginx.conf; server and location are nested inside it. Common bad snippet that triggers errors (do not put http inside server):

Apply changes gracefully: reload vs restart

Prefer reloading the configuration so worker processes are replaced without dropping connections.
  • Reload (graceful): nginx -s reload or sudo systemctl reload nginx
  • Restart (full stop/start): sudo systemctl restart nginx
Avoid restart unless necessary. restart interrupts active connections briefly; reload applies configuration changes without downtime when nginx -t reports OK.
Always run nginx -t and then nginx -s reload (or systemctl reload nginx) if the test is successful. Use restart only for recovering failed workers or replacing the master process.

Main configuration and logging

The global configuration file /etc/nginx/nginx.conf contains the http block and global logging settings. When hosting multiple sites, configure per-site logs to simplify debugging. Example of key sections in /etc/nginx/nginx.conf:
Note: It’s safer to leave defaults (like worker_processes) unless you understand the performance implications. Configure each virtual host to write to its own log directory. Create the directory before reloading NGINX — NGINX will create files but not parent directories. Example server block for a site with per-site logs:
Create log directory and set ownership

Verify reachability with curl

Use curl from the server to check whether NGINX serves requests. This distinguishes between NGINX, DNS, and firewall issues. Examples:
If NGINX is stopped, curl will fail — indicating the service is the problem:

Hosts file for local resolution

For testing or when the server needs to resolve its own hostname, add entries to /etc/hosts. Example:

Firewalls and cloud provider security

Confirm both the server firewall (UFW, firewalld) and any cloud security groups (AWS Security Groups, GCP firewall rules, etc.) allow required ports (80 and 443). Example ufw status output:
Why port 80 still matters
  • Even if your site redirects HTTP to HTTPS, leaving port 80 closed prevents users visiting http://example.com from being redirected. Best practice: keep both 80 and 443 reachable and redirect HTTP to HTTPS.

TLS & protocol considerations

Tune TLS settings carefully. Removing older TLS versions improves security but may block very old clients. Example TLS line to restrict to modern versions:

Common errors and quick fixes

Final troubleshooting checklist

  • Run: nginx -t to validate syntax.
  • If nginx -t is OK: reload with nginx -s reload (or systemctl reload nginx).
  • Check logs in /var/log/nginx/ and per-site log directories.
  • Use curl locally (curl -I) to verify a working response.
  • Verify firewall and cloud security groups allow required ports.
  • If changing log paths, ensure directories exist and ownership is correct.
  • Confirm TLS settings are compatible with your clients.
Thanks for reading — I appreciate it.

Watch Video