How to Find and Review Nginx and Apache Access Logs

· Original article ↗

Summary

A practical guide to locating and exporting Nginx and Apache logs on Linux and in containers, accounting for rotation and proxies, and reviewing request patterns that may indicate scanning or exploitation.

Key points

  • On Debian and Ubuntu, Nginx and Apache logs are typically under /var/log/nginx and /var/log/apache2; RHEL-based Apache commonly uses /var/log/httpd.
  • Check effective server and virtual-host configuration for custom log paths and formats; Debian-based Apache may also log virtual hosts to other_vhosts_access.log.
  • Containerized Nginx may send access and error logs to stdout and stderr; Docker and Kubernetes log commands can export them.
  • Include rotated logs when reviewing activity, and collect error logs alongside access logs for additional context.
  • Behind a proxy or load balancer, requests may show the proxy's IP unless real-client logging is configured; forwarded headers or proxy logs may contain the client address.
  • Repeated requests for sensitive paths, exploit-like strings, suspicious POSTs, or unusual user agents can indicate scanning or attempted exploitation, but require investigation.
  • Review log sanitization before uploading logs because query strings may contain session tokens.

Article Details

Defense Focus
Locate, export, and review web-server access and error logs to detect scanning, exploit attempts, and possible web-shell activity.
Detection Methods
  • Look for bursts of 404 requests targeting paths such as /.env, /.git/config, /wp-login.php, and /phpmyadmin.
  • Search request URLs for traversal strings, ${jndi:, SQL-injection patterns such as union select, and script tags.
  • Investigate successful POST requests to unusual files in upload directories, including other requests made by the same IP.
  • Identify user agents such as sqlmap, nikto, and nuclei.
  • Correlate spikes in 5xx responses with unusual preceding requests.
  • Review access and error logs together; check proxy logs or logged X-Forwarded-For values when requests appear to originate from a proxy.
Data Sources
  • Nginx access and error logs, including rotated files
  • Apache access and error logs, including virtual-host logs and rotated files
  • Container stdout and stderr logs
  • Proxy or load-balancer logs
  • X-Forwarded-For values, when logged
  • Cluster log-collector data when a pod has been replaced
Rule Types
  • Web-server log detection rules
  • Log-pattern detections for scanning and exploit attempts
  • Access/error-log correlation
Platforms
  • Linux web-server hosts
  • Containerized deployments
  • Kubernetes deployments
  • Centralized log collectors
Defensive Actions
  • Confirm effective access-log and error-log paths from the server configuration, including custom virtual-host paths.
  • Include rotated logs when exporting; use zcat -f to read plain and compressed files.
  • Collect both access and error logs for the same time period.
  • For containerized servers, export stdout and stderr logs and check the cluster log collector if a pod was replaced.
  • Verify whether real client IP logging is configured behind a proxy; consult proxy logs or X-Forwarded-For when appropriate.
  • Check the configured log format before uploading or parsing logs.
  • Review sanitized log contents before proceeding, since query strings may contain session tokens.

MITRE ATT&CK

Products

Related Articles