October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk11 min

How to Collect Nginx and Apache Logs With Logstash

Learn how to collect NGINX and Apache access and error logs with Logstash, including path discovery, parser routing, Grok patterns, ECS choices, Filebeat/syslog trade-offs, and rotation recovery.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Logstash’s file input for logs stored on the same host, or receive events from Filebeat or syslog when another agent already ships them. Identify the real access and error paths first, route those streams separately, parse each deployed format, convert the source timestamp, and only then send validated events to Elasticsearch or another supported destination.

Plan the pipeline before writing configuration

NGINX and Apache do not produce one universal log format. Access logs describe HTTP requests; error logs describe warnings, failures, process details, and severity. Treating both as the same stream produces avoidable Grok failures and misleading fields.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A reliable Logstash design has five stages:

  1. Discover paths and formats. Read the running web-server configuration and package layout instead of copying a path from another machine.
  2. Ingest. Use a local file input, Filebeat, or a syslog input according to where the log bytes are available.
  3. Route. Mark the source as NGINX or Apache and as access or error before parsing.
  4. Parse and normalize. Apply the matching Grok pattern, convert the source timestamp, and choose an ECS field strategy.
  5. Validate and deliver. Keep the original message, inspect events with rubydebug, tag failures, and index only after rotation and restart tests pass.

This separation also lets you change an NGINX pattern without risking Apache events, and lets dashboards distinguish request volume from operational errors.

Find the actual NGINX and Apache log files

NGINX paths and formats

NGINX commonly writes access and error logs to different files, but the path depends on the operating system, package, container image, and local configuration. Inspect the active http, server, and location blocks for access_log and error_log. The error_log directive also sets the minimum severity recorded, so two hosts can have different error volume even when their paths match.

#1 Best Overall
Sale
TOZO A1 Wireless Earbuds Bluetooth 5.3 Light Weight in Ear Headphones | IPX5 Waterproof,2 Mics for AI Calls,Immersive Premium Sound Bass Headset with Charging Case,32 EQ via App Black
  • [Ultra-Lightweight Ear Buds Designed for Small Ears] Each earbud weighs only 3.7g and features a compact, ergonomic in-ear design made especially for small ears. Secure, low-profile, and comfortable for workouts, all-day wear or overnight sleeping.The ultra-slim profile sits flush in your ear with no hard edges poking or rubbing, so you can even sleep on your side without discomfort.
  • [Immersive Stereo Sound with TOZO OrigX Technology] TOZO OrigX tuning delivers clear vocals, balanced mids, and natural stereo sound for music, podcasts, and videos.
  • [Long Battery Life for Daily Use] Get up to 7 hours of playtime on a single charge, with up to 32 hours total using the charging case—ideal for workdays, commuting, and extended listening sessions.
  • [Bluetooth 5.3 & Stable Connection] Bluetooth 5.3 provides fast pairing, stable wireless performance, and reduced dropouts as you move around home or office.
  • [Deep Bass with Clear Vocals] High-performance drivers produce punchy bass while keeping vocals clean and detailed for everyday listening.

Do not assume that every installation uses NGINX’s default access format. The log_format directive may add upstream response time, forwarded addresses, request IDs, virtual-host names, or other fields. Save a representative line from every deployed format and version your Grok pattern with that configuration.

Apache paths and formats

Distribution packages often place Apache logs under /var/log/apache2/ or /var/log/httpd/, but virtual hosts can write elsewhere. Confirm the active CustomLog and ErrorLog directives and check whether a site uses a custom LogFormat. A standard combined access line can be parsed with %{COMBINEDAPACHELOG}; a custom format cannot be assumed to match it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Build a path inventory

For each host, record:

  • the absolute access-log path and error-log path;
  • the configured format name or inline format string;
  • whether logs are local files, container streams, or forwarded through syslog;
  • the account that owns the files and the permissions Logstash or its shipper needs;
  • the rotation utility, filename pattern, compression policy, and retention period.

Use narrow globs. A pattern such as /var/log/nginx/*.log is preferable to ingesting an entire directory that may contain debug dumps, archived files, or unrelated applications.

Choose file input, Filebeat, or syslog

Method Use it when Important behavior Main trade-off
Logstash file input Logstash runs on the web host or has dependable filesystem access. Maintains a read-position registry; start_position => "beginning" affects an initial read only. Logstash must be deployed near every file source and must handle local permissions and state.
Filebeat to Logstash A lightweight shipper already runs on each web host or logs must cross a network boundary. Filebeat tails files and forwards events; Logstash owns central parsing and enrichment. Adds an agent and network path, but reduces the number of full Logstash instances.
Syslog input An existing logging system forwards NGINX or Apache messages by TCP or UDP. Logstash can listen on TCP and UDP and accept a custom grok_pattern; the pattern must expose a parseable timestamp. Syslog framing, transport reliability, and sender-side truncation become part of troubleshooting.

Prefer the local file input when the files and Logstash are on the same machine and you need direct control over rotation state. Prefer Filebeat when you need buffering at the edge, centralized Logstash, or a separate process with limited privileges. Use syslog when forwarding is already standardized; do not introduce it solely to avoid configuring a file tailer.

Build a local-file pipeline

The following skeleton covers common package locations while leaving parsing decisions to conditionals. Adjust paths to the inventory from your hosts.

Rank #2
Sale
Smart Watch for Men Women Compatible with iPhone Samsung Android Phone 1.69 inch Full Touch Screen IP68 Waterproof Bluetooh Fitness Tracker Heart Rate/Sleep Monitor (Black)
  • 【IP68 Waterproof Multifunctinal Smart Watch】Torjalph fitness activity tracker smart watch is IP68 waterproof technology ,you can wear it when swimming,handwashing,it's rain-proof which means that you perform multiple exercise modes outside without worrying about sweat or rain corroding your fitness smart watch,and this watch equipped with a 230 mAh large capacity battery magnetic charging ,and this sports activity tracker watch can be used 5-7 days If fully charged.
  • 【Larger 1.83'' Full Screen Watch & Multi-dial Selection】1.83 inch full HD color touch screen smart watch for men / women provides excellent 240*284 resolution image quality ,This Bluetooth smart watch offers a better touch experience and remarkable immersion and ,more than 200 watch faces for you to choose from App"Da Fit ", you can change the dial style according to your mood to wear keeping the world on your wrist
  • 【Accurate Activity Tracker Smart Watch 】sports watch activity tracker uses sweat and dust resistant breathable silicone strap, our Fitness Tracker Smart Watch for Android iOS Phones supports 12 sports modes,walking,running,bicycle,swimming,badminton,basketball,football,rope skipping. This bluetooth calls smart watch for men women is lightweight and stylish, bringing more convenient and relaxing sports experience while also providing more protection.
  • 【Your 24 Hour Personal Daily Health Monitor】Fitness watch for women men full touch screen IP67 waterproof bluetooth smartwatch for Android iOS Phones with heart rate blood pressure monitor multifunction Andriod smart watch with steps counter sleep monitor sports fitness watch, monitoring blood oxygen saturation allows you to understand your physical condition in real time to track fitness progress ,to know your health status in time.
  • 【More Functions Bluetooth Call Smart Watch】This fitness activity smart watch full screen for iPhone and Android phones includes a bunch of new features including:The bluetooth smart watch can hang up the phone, receive and display WhatsAPP /Text /Facebook /Twitter /Messenger reminder.Support sedentary reminder, alarm clock, stopwatch, timer,weather information,music control, remote camera control compatible with Android 5.0 and above or iOS 9.0 and above smartphones.
input {
  file {
    path => [
      "/var/log/nginx/*.log",
      "/var/log/apache2/*.log",
      "/var/log/httpd/*.log"
    ]
    start_position => "beginning"
  }
}

filter {
  if [path] =~ /apache/ and [path] =~ /(access|combined)/ {
    mutate { add_field => { "[service][name]" => "apache" "[log][type]" => "access" } }
    grok { match => { "message" => "%{COMBINEDAPACHELOG}" } }
    date { match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ] }
  } else if [path] =~ /nginx/ and [path] =~ /(access|combined)/ {
    mutate { add_field => { "[service][name]" => "nginx" "[log][type]" => "access" } }
    # Apply the pattern that matches the deployed NGINX log_format.
  } else {
    # Route NGINX and Apache error files to their own patterns.
  }
}

output {
  elasticsearch { hosts => [ "https://your-cluster.example" ] }
  stdout { codec => rubydebug }
}

The example uses the conventional path metadata supplied by the file input. If your naming scheme does not contain words such as access or error, add explicit fields with separate input blocks or tags so routing does not depend on a fragile filename test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep stdout { codec => rubydebug } during development. It shows the resulting field structure, tags, timestamps, and unparsed data before you commit an index mapping.

Parse Apache combined access logs

Use the built-in combined pattern

For the standard Apache combined format, Grok’s %{COMBINEDAPACHELOG} pattern extracts the client address, identity fields, authenticated user, timestamp, request line, status, response size, referrer, and user agent. Apply a date filter immediately afterward:

grok {
  match => { "message" => "%{COMBINEDAPACHELOG}" }
  tag_on_failure => [ "_apache_access_grok_failure" ]
}
date {
  match => [ "timestamp", "dd/MMM/yyyy:HH:mm:ss Z" ]
  tag_on_failure => [ "_apache_access_date_failure" ]
}

The date filter turns the textual request time into Logstash’s event timestamp. Keep the original message even after parsing; it is the forensic copy you need when a format changes or a field looks suspicious.

Handle non-combined Apache access formats

Common customizations remove the referrer or user-agent, add virtual-host names, or append request duration and forwarded addresses. In those cases, copy the exact LogFormat order into a custom pattern. Do not force a combined pattern to consume a line that has different quoting or field count. Put the custom pattern in a named version, such as apache_access_v2, and update it with the web-server configuration.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
New Bee Guitar Cable 10ft Electric Instrument Bass AMP Cord
  • [Low Noise High Fidelity] New bee guitar cord with 22AWG oxygen-free-copper center conductors provides enhanced signal transfer, the PVC insulation material and the high-density stranded copper double shield provide noise rejection for quiet operation
  • [Ideal for Choice] New bee 1/4 straight and right angle metal connectors, ensures a secure connection in any instrument, pedal, or amp jack. L shape great fro on stage guitar stands
  • [Wide Compatible] Suitable for mixer, power amplifier, microphone, effector, decoder, equalizer, electoronic organ, electric guitar, electric bass and other electronic equipments. Widely used in the installation of smart home, karaoke speaker, professional stage audio, etc
  • [Easy Disassemble] Making incidental repairs quick and easy! Very nice, flexible cable
  • [Dont Hesite to Order] 24 hours customer services and professional technology team are standing by

Parse Apache error logs separately

Apache error lines are not combined access records. Their grammar varies by Apache version and module and can include a timestamp, severity, process or module identifier, client address, and free-form text. Route files whose configured destination is an error log to a dedicated Grok pattern, capture severity into [log][level], and retain the remainder as a message. If a module emits multiline diagnostics, configure and test multiline handling at the shipper or input layer rather than joining unrelated events in the filter.

Parse NGINX access and error logs

Match the deployed access format

NGINX access fields are defined by log_format. A minimal combined-style format might be represented by a pattern like this:

grok {
  match => {
    "message" => "%{IPORHOST:[client][address]} - %{DATA:[user][name]} [%{HTTPDATE:[nginx][access][time]}] "%{WORD:[http][request][method]} %{DATA:[url][original]} HTTP/%{NUMBER:[http][version]}" %{INT:[http][response][status]:int} %{INT:[http][response][body][bytes]:int} "%{DATA:[http][request][referrer]}" "%{DATA:[user_agent][original]}""
  }
  tag_on_failure => [ "_nginx_access_grok_failure" ]
}
date {
  match => [ "[nginx][access][time]", "dd/MMM/yyyy:HH:mm:ss Z" ]
}

This is only an example for a format with those fields. If the configuration appends upstream timing, forwarded-for values, request IDs, or another delimiter, extend the pattern in the same order. Keep the raw line and tag failures so a newly deployed format is visible instead of silently disappearing.

Parse NGINX error logs

NGINX error lines normally carry an ISO-like timestamp, severity, process information, and a free-form message. A pattern must follow the exact punctuation emitted by your version and configuration. Conceptually, route the line as follows:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
grok {
  match => {
    "message" => "[%{TIMESTAMP_ISO8601:[nginx][error][time]}] [%{LOGLEVEL:[log][level]}] %{GREEDYDATA:[message]}"
  }
  tag_on_failure => [ "_nginx_error_grok_failure" ]
}
date {
  match => [ "[nginx][error][time]", "ISO8601" ]
}

Some builds include a process ID and connection number between severity and message; capture those pieces only after comparing several real lines. Error-log severity is controlled by error_log, so document the configured level alongside the pipeline.

Rank #4
BSIMB 15.6" Digital Family Calendar & Chore Chart, No Subscription Fees
  • Digital Family Calendar: BSIMB digital calendar wall touch screen puts an end to your chaotic life. Designed for busy families, the digital calendar keeps you organised and in step with your family. Assign different colours and tasks to each family member to make family scheduling easier and more intuitive.
  • Easy Setup and Auto-Sync: Plug in, connect to WLAN and auto-syn your electric calendar in minutes. Digital wall calendar compatible with Google calendar, iCloud calendar, Outlook calendar, Cozi calendar and Yahoo calendar. Add events directly on the device or through the ecalendar app. Electronic calendar stays current whether you're at work or traveling—no manual updates needed.
  • All-In-One Home Assistant: Smart calendar builds habits and encourage independence with personalised chores. Display daily meal plan to reduce the daily ‘What's for dinner?’ stress. To-do lists keep track of everything you want. Turning chores into valuable achievements with stars and rewards, making life easier and more enjoyable.
  • Manage Anytime Anywhere: BSIMB electronic calendar for family stay connected with the powerful ecalendar app. Access and manage your digital wall calendar anytime, anywhere with free features like stars & rewards, photo screensaver, chore charts, meals plans, to-do lists etc. Electronic planner paid features like Magic Import tailor advanced tools for users with special needs.
  • Stay in Touch with Loved Ones: Share photos or videos from your phone to electronic wall calendar with app, instantly update your life moment, and keep in touch with your family, especially those who are far away; you can also surprise your smart calendar digital wall by sending him a wish card; it's also great for keeping tech-illiterate elders in touch with the youngsters.

Use ECS deliberately

Grok composite patterns can emit different field names when ecs_compatibility is enabled. Decide whether your index templates, dashboards, alert rules, and queries expect ECS-compatible fields before changing this setting. A pipeline that mixes legacy and ECS names for client address, user agent, status, or bytes becomes difficult to query.

Whichever mode you choose:

  • keep service identity in a consistent field such as [service][name];
  • keep access versus error classification in [log][type] or an equivalent documented field;
  • preserve source-specific details under a namespace such as [nginx] or [apache] when no common ECS field exists;
  • define index templates before production ingestion so numeric status and byte fields are not mapped as strings;
  • record the selected compatibility mode in the pipeline repository and deployment documentation.

Elasticsearch is used in many documented Logstash examples, but the parsed event can be sent to any supported output after you have inspected the field structure and mapping behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Understand file state, rotation, and restarts

Read-position registry

The file input stores how far it has read in a registry. start_position => "beginning" controls what happens when a file is first registered; it does not replay content whose position is already recorded. Deleting or relocating the registry can therefore cause old lines to be ingested again, while a damaged or inaccessible registry can make recovery behavior surprising.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Rotation and truncation tests

Test the exact rotation method used by the host:

  • rename the active file and create a new file with the original name;
  • copy-truncate the file if that is what the rotation utility does;
  • compress the old file and verify the glob does not ingest the archive unexpectedly;
  • restart Logstash during rotation and confirm that neither the tail nor the beginning of the new file is skipped;
  • check behavior after a host reboot and after restoring the registry from backup.

Never point a production glob at rotated archives unless replay is intentional. If duplicate events appear, compare inode, filename, registry state, and rotation timestamps before changing filters.

Permissions and delayed files

Grant the collecting process read access without making the entire log directory writable. Verify access to newly created files, not only the file that existed during installation. A permission change at rotation can look like a parser outage because no new events arrive.

Ship logs with Filebeat

When Filebeat already tails the web-server files, keep collection and parsing responsibilities separate. Configure one or more file paths at the edge, add fields identifying NGINX or Apache and access or error, and send the events to Logstash. The central pipeline can then use those fields instead of guessing from a filename that may not survive transport.

Validate the handoff with one access line and one error line from every format. Confirm that the event timestamp survives serialization, that the original message is intact, and that back-pressure does not cause the shipper to discard data. Filebeat is especially useful when Logstash should not run with direct access to application log directories.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Receive forwarded events with syslog

The Logstash syslog input can listen on TCP, UDP, or both. Select the transport that matches the sender’s reliability requirements and firewall policy. If the sender wraps a web-log line in a non-standard envelope, provide a custom grok_pattern that captures a timestamp Logstash can parse. Test for message truncation, embedded brackets, quoted request lines, and timezone offsets.

Syslog transport does not remove the need to distinguish access from error records. Use a sender-provided program or facility field when available; otherwise route based on a stable tag or source metadata. Do not parse a syslog envelope and an HTTP access line with one oversized pattern: strip or capture the envelope first, then apply the web-server parser.

Validate events before indexing

Minimum test set

  1. Capture one normal access line, one line with a quoted referrer containing spaces, and one line with a non-200 status.
  2. Capture one NGINX error at each severity that the host records and one Apache error containing module or client context.
  3. Send each sample through the pipeline with rubydebug enabled.
  4. Confirm that the parsed timestamp is the event time, not ingestion time, and that timezone information is retained.
  5. Check integer mappings for status, bytes, process IDs, and durations.
  6. Verify that malformed lines receive a source-specific failure tag and remain searchable through the original message.

Useful failure branches

  • No events: check path expansion, permissions, registry location, rotation timing, and whether the input host can see the files.
  • Everything has _grokparsefailure: compare a real line with the active format, including optional fields, quoting, and timezone.
  • Only error logs fail: confirm they are not being sent through COMBINEDAPACHELOG or an NGINX access pattern.
  • Timestamps are wrong: inspect the captured field, date pattern, locale, and offset; place the date filter after Grok.
  • Events duplicate after restart: inspect the file-input registry and any manual deletion or relocation of state.
  • Fields change after an upgrade: compare the web-server configuration and the Logstash Grok plugin’s ECS setting, then version the parser.

Operational checklist

  • Confirm active NGINX access_log/error_log and Apache CustomLog/ErrorLog paths.
  • Collect a sample from every access and error format actually deployed.
  • Use narrow globs and explicit source metadata.
  • Keep access and error parsers in separate conditionals.
  • Parse source timestamps and preserve the raw message.
  • Choose ECS compatibility before creating dashboards and mappings.
  • Tag and monitor parse failures instead of dropping unmatched lines.
  • Test permissions, rotation, truncation, multiline behavior, restart recovery, and registry backup.
  • Retain stdout { codec => rubydebug } until field names and types are verified.

With those controls in place, Logstash can collect both servers without pretending their formats are interchangeable: local files are tailed with durable state, forwarded events retain source metadata, each stream receives the parser it needs, and indexed timestamps and fields remain usable when configurations evolve.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.