How to Read Nginx Access Logs for Attack Signs
On your web server, read /var/log/nginx/access.log. Look for odd paths (/wp-login.php on a non-WordPress site), long query strings, and repeated 404 spikes from one IP. Start with sudo tail -n 200 and a few grep filters.
Quick answer
sudo tail -n 50 /var/log/nginx/access.log
sudo grep -E 'wp-login|xmlrpc|\.env|phpunit|/admin' /var/log/nginx/access.log | tailWhy read access logs?
Your access log is a diary of every request. Attackers leave footprints: scans for .env, WordPress logins, PHPUnit RCE paths. Nora in Oslo and Manish in Hubli review theirs after any odd spike in traffic.
What does a line look like?
Combined format usually has IP, time, method, path, status, bytes, user-agent.
203.0.113.9 - - [27/Oct/2026:10:11:12 +0530] "GET /.env HTTP/1.1" 404 125 "-" "curl/8.0"What it means: This bot asked for .env and got 404 — probe failed. Good.
How do I hunt step by step?
- View recent lines:
sudo tail -n 50 /var/log/nginx/access.logWhat it means: See the newest traffic first.
- Common probes:
sudo grep -E 'wp-login|xmlrpc|\.env|\.git|phpunit' /var/log/nginx/access.log | tail -n 20198.51.100.20 ... "GET /wp-login.php HTTP/1.1" 404 198.51.100.20 ... "GET /.git/config HTTP/1.1" 404What it means: Same IP tried CMS and git metadata paths. Noise if all 404.
- Top talkers:
sudo awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | headWhat it means: Ranks source IPs by request count.
- Unexpected successes on odd paths:
sudo awk '$9==200 && $7 ~ /env|git|phpunit|wp-login/ {print}' /var/log/nginx/access.log | tailWhat it means: 200 on those paths deserves urgent review.
- If something looks real, follow Is my website hacked? and rotate secrets.
Ravindra Bagale's Tip
A probe is not always a breach. Hundreds of 404s for wordpress paths on a static site are normal internet noise. Worry more about 200 responses to strange URLs. Keep logs rotated so the disk does not fill.
Ravindra Bagale's Tip – मराठी
Probe म्हणजे नेहमी breach नाही. Static साइटवर wordpress path चे शेकडो 404 सामान्य गोंगाट आहेत. विचित्र URL ला 200 मिळाल्यास जास्त काळजी करा. Logs rotate करा जेणेकरून disk भरणार नाही.
Ravindra Bagale's Tip – हिंदी
Probe हमेशा breach नहीं। Static साइट पर wordpress path के सैकड़ों 404 आम शोर हैं। अजीब URL पर 200 मिले तो ज़्यादा चिंता करो। Logs rotate रखो ताकि disk न भरे।
Quick quiz: check what you learned
Many 404s for /wp-admin/ on a non-WordPress site usually mean:
- Internet bots probing common paths
- Your site is definitely WordPress
- SSH daemon is broken on the host
- DNS is completely offline today
Show answer
A. Bots spray common CMS paths; block or ignore noise.
Which field in a typical nginx log shows the client IP?
- The first field (remote address)
- The HTTP status code number only
- The request time in milliseconds
- The User-Agent string at the end
Show answer
A. Default combined format starts with $remote_addr.
Learn it properly
This guide is the short path. These pages go deeper, with labs:
Frequently asked questions
Where is the Nginx access log?
Usually /var/log/nginx/access.log on Linux.
What paths are common probes?
/wp-login.php, /xmlrpc.php, /.env, /.git/config, /vendor/phpunit.
Does a hit on /.env mean I was hacked?
Not by itself. If the response was 404, the probe failed. If it was 200 and secrets leaked, treat it as an incident.
Related tool?
Is my website hacked? checklist under /cyber/tools/.
Related lesson?
31.2 Where logs live; 19.10 How defenders detect scanning.