Nginx error logs can be tough to decipher, even for experienced sysadmins and DevOps engineers. They hold valuable clues about whatβs going wrong, but sorting through them can feel overwhelming.
Understanding these logs doesnβt have to be a challenge. This guide breaks them down in a clear, practical wayβso you can find the issues that matter and fix them with confidence.
What Exactly Is the Nginx Error Log?
The nginx error log is your server's diary where it records all its complaints, warnings, and outright failures. Unlike access logs that track who's knocking on your door, error logs tell you when something's broken and why.
Default location? Usually /var/log/nginx/error.log
, but it depends on your setup. Some distros might place it in /var/log/nginx/error.log
, while others use /usr/local/nginx/logs/error.log
.
Here's a quick look at what these logs contain:
- Timestamp of when stuff went sideways
- Error severity level (from "meh" to "everything's on fire")
- Process ID and thread ID (which part of nginx hit the problem)
- Client IP address (who triggered the error)
- The actual error message (the meat of the issue)
Nginx Error Log: 8 Essential Log Levels Explained
Before jumping into troubleshooting, let's make sure your logs are giving you the right info. Add this to your nginx.conf:
error_log /path/to/error.log warn;
That warn
part? That's your log level.
Here are your options:
Log Level | What It Gives You | When to Use It |
---|---|---|
debug |
Everything. Seriously, everything. | During development or when hunting elusive bugs |
info |
Informational messages + warnings + errors | General monitoring in non-critical environments |
notice |
Noteworthy events + warnings + errors | Standard production setting for attentive admins |
warn |
Warnings + errors | Good balance for production (recommended) |
error |
Only errors | When your logs are getting too big |
crit |
Critical issues only | When disk space is tight (not recommended) |
alert |
Action must be taken immediately | Rarely used |
emerg |
System is unusable | Rarely used |
Pro tip: Different servers, different needs. You can set specific log levels for different virtual hosts:
server {
listen 80;
server_name example.com;
error_log /var/log/nginx/example.com.error.log warn;
# rest of your config...
}
4 Common Nginx Error Log Messages and How to Fix Them Fast
Let's decode some of the most common head-scratchers you'll find in your nginx error log.
"connect() failed"
2023/07/15 14:22:31 [error] 12345#0: *67 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.1, server: example.com, request: "GET /api/data HTTP/1.1", upstream: "http://127.0.0.1:8080/api/data", host: "example.com"
What it means: Nginx can't connect to your backend service. It's knocking, but nobody's home.
How to fix it:
- Check if your backend service is running:
systemctl status your-backend-service
- Verify the upstream server address and port are correct
- Check firewall rules:
iptables -L
orufw status
"directory index of [path] is forbidden"
2023/07/15 15:33:42 [error] 12345#0: *68 directory index of /usr/share/nginx/html/ is forbidden, client: 192.168.1.1, server: localhost, request: "GET / HTTP/1.1", host: "example.com"
What it means: Someone tried to view a directory listing, but you haven't enabled it.
How to fix it:
- If you want to allow directory listings, add
autoindex on;
to your server or location block - If not, create an index.html file in that directory
"no live upstreams while connecting to upstream"
2023/07/15 16:44:53 [error] 12345#0: *69 no live upstreams while connecting to upstream, client: 192.168.1.1, server: example.com, request: "GET /api/data HTTP/1.1", upstream: "http://backend/api/data", host: "example.com"
What it means: All your backend servers in an upstream group are down. It's like calling a restaurant and all the lines are busy.
How to fix it:
- Check the health of each upstream server
- Review your upstream configuration for typos
- Consider adding more backup servers
"client intended to send too large body"
2023/07/15 17:55:04 [error] 12345#0: *70 client intended to send too large body: 21474836480 bytes, client: 192.168.1.1, server: example.com, request: "POST /upload HTTP/1.1", host: "example.com"
What it means: Someone's trying to upload a file bigger than your config allows.
How to fix it:
- Increase the limit with
client_max_body_size 20M;
in your server or location block - Adjust based on your actual needs, don't go crazy
3 Attack Patterns to Watch For in Nginx Error Logs
Your error logs aren't just for fixing stuff β they're your early warning system for security threats.
Detecting Potential Attacks
Keep an eye out for these red flags:
- Unusual HTTP methods: If you see a bunch of TRACE or CONNECT requests in your error logs, someone might be probing your server.
2023/07/15 18:06:15 [error] 12345#0: *71 client sent invalid method while reading client request line, client: 192.168.1.1, server: example.com
- 404 errors to suspicious paths: Lots of 404s to
/wp-admin
,/phpmyadmin
, or.env
files could mean someone's scanning for vulnerabilities.
2023/07/15 19:17:26 [error] 12345#0: *72 open() "/usr/share/nginx/html/wp-admin/index.php" failed (2: No such file or directory), client: 192.168.1.1, server: example.com, request: "GET /wp-admin/index.php HTTP/1.1", host: "example.com"
- Buffer overflow attempts: Long, weird requests might be trying to crash your server or inject code.
2023/07/15 20:28:37 [error] 12345#0: *73 client sent too long URI, client: 192.168.1.1, server: example.com
Real-time Monitoring Setup
Don't wait until it's too late. Set up real-time monitoring with this approach:
- Consider a centralized logging system like Kibana or Grafana Loki where you can create dashboards and alerts.
Set up fail2ban to automatically block suspicious IPs:
# Example fail2ban filter for nginx
[Definition]
failregex = ^ \[error\] \d+#\d+: \*\d+ connect\(\) failed .*, client: <HOST>
ignoreregex =
Use tail
to actively watch your logs:
tail -f /var/log/nginx/error.log | grep -E 'error|critical|alert|emergency'
3 Critical Performance Monitoring Indicators in Your Logs
Your nginx error log can reveal performance bottlenecks before they become customer complaints.
Key Performance Indicators to Watch
Timeouts:
2023/07/15 23:01:10 [error] 12345#0: *76 upstream timed out
Fix: Check your backend service performance and consider adjusting proxy_read_timeout
.
Buffer issues:
2023/07/15 22:50:59 [error] 12345#0: *75 upstream sent too big header
Fix: Increase proxy_buffer_size
and proxy_buffers
values.
Worker connections exceeded:
2023/07/15 21:39:48 [error] 12345#0: *74 worker_connections are not enough
Fix: Increase worker_connections
in your nginx.conf.
Log Rotation and Management
Your logs are useful, but they can eat up disk space faster than a hungry teenager clears out a fridge. Set up proper log rotation:
# /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 nginx adm
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
This config:
- Rotates logs daily
- Keeps logs for 14 days
- Compresses old logs
- Signals nginx to reopen log files without restarting
Advanced Troubleshooting Techniques for Nginx Users
When the usual fixes aren't cutting it, try these power-user moves.
Using Debug Logging Temporarily
When you've got a tricky issue, crank up the detail:
# Add to the server block you're troubleshooting
error_log /var/log/nginx/debug.log debug;
Just remember to turn it off after β debug logs get huge fast.
Correlating Access and Error Logs
The real magic happens when you combine both logs. If you see errors for specific requests, check the access log for the same client IP and timestamp:
grep "192.168.1.1" /var/log/nginx/access.log | grep "15/Jul/2023:14:22"
Custom Error Pages with Better Diagnostics
Make your error pages work for you with extra debugging info:
server {
# Your other config...
error_page 500 502 503 504 /custom_50x.html;
location = /custom_50x.html {
root /usr/share/nginx/html;
internal;
# This adds the upstream status to your error page
fastcgi_param UPSTREAM_STATUS $upstream_status;
}
}
5 Essential Tools That Make Nginx Error Log Analysis Easy
1. ELK Stack (Elasticsearch, Logstash, Kibana)
For large-scale, production-grade setups, ELK is one of the most powerful solutions available. It allows you to collect, process, and visualize Nginx error logs efficiently.
- Elasticsearch indexes and stores logs for fast searching.
- Logstash ingests and transforms logs before sending them to Elasticsearch.
- Kibana provides an intuitive interface for visualizing and analyzing logs.
Using ELK, you can set up dashboards, track error trends, and detect anomalies in real time. This makes troubleshooting Nginx issues faster and more structured.
2. Grafana Loki
If ELK feels like overkill, Grafana Loki is a lightweight alternative. Itβs designed specifically for log aggregation and pairs well with Prometheus for monitoring.
- Ideal for Kubernetes environments, where logs are distributed across multiple containers.
- No need for full-text indexing, making it more efficient in terms of storage.
- Integrates with Grafana, allowing you to visualize Nginx logs alongside other metrics.
With Loki, you can centralize and query logs in a way that feels intuitive, making troubleshooting much easier.
3. Last9
Last9 is a cloud-native observability platform that correlates Nginx error logs with infrastructure performance. Unlike traditional log management tools, Last9 provides real-time insights by correlating logs with system and application metrics.
After integrating Last9 with Nginx logs:
- You can view collated logs and metrics in the Last9 dashboard.
- Smart alerting helps detect patterns and anomalies before they cause outages.
- Context-aware analysis allows you to troubleshoot with deeper insights, rather than sifting through endless log files.
For teams managing distributed applications, Last9 simplifies observability by making logs more actionable.

4. Lnav (Log File Navigator)
Sometimes, a simple yet powerful log viewer is all you need. Lnav is a command-line tool that makes browsing and analyzing logs easier. Unlike cat
or grep
, Lnav provides syntax highlighting, filtering, and real-time updates.
Example usage:
lnav /var/log/nginx/error.log
- Color-coded output makes it easier to spot errors and warnings.
- Automatic log format detection saves time configuring parsers.
- Live monitoring mode lets you view logs as they update.
If you prefer a fast, local tool that requires minimal setup, Lnav is a great option.
5. GoAccess
If you want a real-time, interactive log analysis tool, GoAccess is a great choice. Unlike Lnav, which focuses on browsing logs, GoAccess summarizes and visualizes log data.
Example usage:
goaccess /var/log/nginx/error.log -o report.html --log-format=COMBINED
- Generates detailed reports with key metrics like request count, response codes, and error trends.
- Provides both a terminal-based UI and HTML reports, making it easy to share insights.
- Ideal for quick log analysis, especially when investigating traffic patterns or security incidents.
Conclusion
Your nginx error log isn't just a file β it's your server's way of communicating with you.
Remember:
- Check your logs regularly, not just when there's a fire
- Set the right log level for your environment
- Use automated tools to monitor for security threats
- Rotate your logs before they fill your disk
FAQs
How do I enable error logging in Nginx?
Error logging is enabled by default in nginx. To customize it, add error_log /path/to/error.log level;
to your nginx.conf file, where level is debug, info, notice, warn, error, crit, alert, or emerg.
Why are my Nginx error logs empty?
This could mean one of three things: you're looking at the wrong log file location, your log level is set too high (try lowering it to notice or info), or β congratulations β your server is running perfectly.
How do I find the Nginx error log location?
Check your nginx.conf file with grep "error_log" /etc/nginx/nginx.conf
or use nginx -T | grep error_log
to see all error log configurations across your included files.
Can I log errors to syslog instead of a file?
Yes, use error_log syslog:server=unix:/dev/log,facility=local7,tag=nginx,severity=error;
in your config to send errors to syslog.
How do I handle "too many open files" errors in Nginx?
Increase the limit by adding worker_rlimit_nofile 65535;
to your nginx.conf and update your system limits in /etc/security/limits.conf
for the nginx user.
What's the difference between nginx access and error logs?
Access logs record all requests to your server (who visited what), while error logs record problems and issues (what went wrong and why).
How can I filter out specific errors from my logs?
You can't filter what nginx writes, but you can filter what you see using grep. For example: cat error.log | grep -v "favicon.ico"
to exclude all favicon errors.
Is it normal to see some 404 errors in nginx error logs?
Yes, 404 errors are common and often harmless β they just mean someone requested a file that doesn't exist. However, patterns of 404s to sensitive areas could indicate security scanning.