{"id":28002943,"url":"https://github.com/spithash/nginx-logresolver","last_synced_at":"2025-05-09T01:45:24.850Z","repository":{"id":291955984,"uuid":"979335545","full_name":"spithash/nginx-logresolver","owner":"spithash","description":"Real-time Nginx log enhancer that resolves IPs to hostnames and optionally colorizes output using grc.","archived":false,"fork":false,"pushed_at":"2025-05-07T13:05:18.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-09T01:45:20.730Z","etag":null,"topics":["bash-script","log-parser","logs","nginx","sysadmin"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spithash.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-07T11:04:08.000Z","updated_at":"2025-05-07T13:05:21.000Z","dependencies_parsed_at":"2025-05-07T12:25:46.746Z","dependency_job_id":"20bb6e1a-e2ed-45f5-9496-c0a96d84368e","html_url":"https://github.com/spithash/nginx-logresolver","commit_stats":null,"previous_names":["spithash/nginx-logresolver"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spithash%2Fnginx-logresolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spithash%2Fnginx-logresolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spithash%2Fnginx-logresolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spithash%2Fnginx-logresolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spithash","download_url":"https://codeload.github.com/spithash/nginx-logresolver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176443,"owners_count":21866142,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash-script","log-parser","logs","nginx","sysadmin"],"created_at":"2025-05-09T01:45:24.341Z","updated_at":"2025-05-09T01:45:24.839Z","avatar_url":"https://github.com/spithash.png","language":"Shell","readme":"# Nginx Log Resolver\n\n`nginx-logresolver` is a Bash script that processes Nginx log files and resolves IP addresses to hostnames. It improves the readability of your logs by replacing IP addresses with their corresponding hostnames. It also caches the results for efficient performance, ensuring that hostnames are looked up only once every 5 hours.\n\n## Why?\n\nBy default, Nginx logs contain raw IP addresses instead of hostnames. This is intentional: resolving hostnames requires DNS lookups, which are relatively slow and can significantly degrade performance—especially under high traffic. For that reason, Nginx avoids hostname resolution in logs to keep things fast and efficient.\n\nHowever, there are many cases where seeing a hostname instead of an IP can be helpful, such as:\n\n- Quickly identifying traffic from known domains or bots\n- Spotting patterns in abuse or suspicious activity\n- Debugging or auditing logs in real-time with more context\n\nThis script bridges that gap by resolving IPs to hostnames **outside of Nginx**, after the logs are written. It runs in real time, uses a cache to minimize DNS overhead, and optionally adds colorized output for better readability—all without modifying your Nginx config or affecting its performance.\n\n## Features\n\n- Resolves IP addresses to hostnames in real-time as Nginx logs are written.\n- Caches hostname lookups for up to 5 hours to reduce the frequency of DNS queries. (stores them to /tmp/ip_cache.txt)\n- Supports multiple log files.\n- Integrates with `grc` (Generic Colourizer) to add color to the log output for easier reading.\n- Efficient and minimal Bash-based solution with minimal dependencies.\n\n## Requirements\n\n- `bash`\n- `getent` for DNS lookups\n- `grc` (Generic Colourizer) for colorized log output (*optional*)\n- `/var/log/nginx/error.log` and `/var/log/nginx/access.log` for Nginx logs (change it to your needs)\n- `tail` linux tail command\n\n## Installation\n\n### Clone the repository:\n\n```bash\ngit clone https://github.com/spithash/nginx-logresolver.git\ncd nginx-logresolver\n```\n## Usage\n\nMake the script executable:\n\n```bash\nchmod +x nginx-logresolver.sh\n```\n## Running the Script\n\nOnce the script is executable, you can start it with:\n\n```bash\n./nginx-logresolver.sh\n```\n\n### What It Does\n\n- **Tails Nginx Logs**: Monitors both `/var/log/nginx/access.log` and `/var/log/nginx/error.log` in real-time.\n- **Resolves IPs to Hostnames**: Converts IP addresses in each log line to hostnames using `getent`.\n- **Uses a Cache**: Saves hostname lookups in `/tmp/ip_cache.txt` and reuses them for 3 hours to reduce DNS lookups.\n- **Adds Color**: Uses `grc` to colorize log output for easier readability.\n\n\n### Example Output\n\n```text\nhost.example.com - - [07/May/2025:10:42:31 +0000] \"GET /index.html HTTP/1.1\" 200 1024 \"-\" \"Mozilla/5.0\"\n```\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspithash%2Fnginx-logresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspithash%2Fnginx-logresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspithash%2Fnginx-logresolver/lists"}