circle-info
Version 2 is coming up

Nginx

Nginx Access Log Streaming Setup Guide

This guide explains how to configure your existing Nginx server to stream access logs in JSON format to Limy's log ingestion endpoint.

Overview

You will:

  1. Update your Nginx configuration to output access logs in JSON format

  2. Install and configure Fluent Bit to stream logs to the Limy endpoint

Choose the setup method that matches your environment:

  • Bare Metal / VM Setup

  • Kubernetes Setup


Bare Metal / VM Setup

Step 1: Configure Nginx JSON Access Logs

Add the following log_format directive to your Nginx configuration's http block (typically in /etc/nginx/nginx.conf):

http {
    # JSON log format with all available fields
    log_format json_combined escape=json '{'
        '"log_type":"nginx_access",'
        '"timestamp":"$time_iso8601",'
        '"time_local":"$time_local",'
        '"msec":"$msec",'

        '"client_ip":"$remote_addr",'
        '"client_port":"$remote_port",'
        '"remote_user":"$remote_user",'

        '"request":"$request",'
        '"request_method":"$request_method",'
        '"request_uri":"$request_uri",'
        '"uri":"$uri",'
        '"args":"$args",'
        '"scheme":"$scheme",'
        '"server_protocol":"$server_protocol",'
        '"request_length":$request_length,'
        '"request_time":$request_time,'

        '"status":$status,'
        '"body_bytes_sent":$body_bytes_sent,'
        '"bytes_sent":$bytes_sent,'

        '"host":"$host",'
        '"server_addr":"$server_addr",'
        '"server_port":"$server_port",'
        '"server_name":"$server_name",'
        '"hostname":"$hostname",'
        '"nginx_version":"$nginx_version",'
        '"pid":"$pid",'

        '"connection":"$connection",'
        '"connection_requests":"$connection_requests",'
        '"pipe":"$pipe",'

        '"http_host":"$http_host",'
        '"http_user_agent":"$http_user_agent",'
        '"http_referer":"$http_referer",'
        '"http_accept":"$http_accept",'
        '"http_accept_encoding":"$http_accept_encoding",'
        '"http_accept_language":"$http_accept_language",'
        '"http_content_type":"$http_content_type",'
        '"http_content_length":"$http_content_length",'
        '"http_x_forwarded_for":"$http_x_forwarded_for",'
        '"http_x_forwarded_proto":"$http_x_forwarded_proto",'
        '"http_x_real_ip":"$http_x_real_ip",'
        '"http_x_request_id":"$http_x_request_id",'

        '"sent_http_content_type":"$sent_http_content_type",'
        '"sent_http_content_length":"$sent_http_content_length",'

        '"upstream_addr":"$upstream_addr",'
        '"upstream_status":"$upstream_status",'
        '"upstream_response_time":"$upstream_response_time",'
        '"upstream_response_length":"$upstream_response_length",'
        '"upstream_connect_time":"$upstream_connect_time",'
        '"upstream_header_time":"$upstream_header_time",'
        '"upstream_cache_status":"$upstream_cache_status",'

        '"ssl_protocol":"$ssl_protocol",'
        '"ssl_cipher":"$ssl_cipher",'
        '"ssl_session_reused":"$ssl_session_reused",'
        '"ssl_server_name":"$ssl_server_name",'

        '"gzip_ratio":"$gzip_ratio"'
    '}';

    # Use the JSON format for access logs
    access_log /var/log/nginx/access.log json_combined;

    # ... rest of your existing configuration
}

Apply the Nginx Configuration


Step 2: Install Fluent Bit

Option A: Debian/Ubuntu

Option B: RHEL/CentOS/Amazon Linux

Option C: Docker


Step 3: Configure Fluent Bit

Create the Fluent Bit configuration file at /etc/fluent-bit/fluent-bit.conf:

Create the parsers file at /etc/fluent-bit/parsers.conf:

Replace the API Key

Replace YOUR_API_KEY_HERE in the configuration with the API key provided to you by Limy.


Step 4: Start Fluent Bit


Kubernetes Setup

Step 1: Update Nginx ConfigMap

If you're using Nginx in Kubernetes, update your Nginx ConfigMap to include the JSON log format. The key change is logging to /dev/stdout so Kubernetes can capture the logs.

Mount this ConfigMap in your Nginx deployment:


Step 2: Create Fluent Bit Secret for API Key

Apply the secret:


Step 3: Deploy Fluent Bit ConfigMap

Note: Replace <your-nginx-app-label> in the Path with your Nginx pod name or label pattern (e.g., *nginx* or *my-app-nginx*).


Step 4: Deploy Fluent Bit DaemonSet


Step 5: Apply Kubernetes Resources


Alternative: Using Helm

If you prefer Helm, you can install Fluent Bit using the official chart:

For more complex configurations, create a values.yaml file and use:


Verification

1. Verify Nginx is Logging in JSON Format

Bare Metal / VM:

Kubernetes:

You should see JSON-formatted log entries like:

2. Verify Fluent Bit is Running

Bare Metal / VM:

Kubernetes:

3. Generate Test Traffic


Troubleshooting

Nginx Configuration Errors

Fluent Bit Issues

Bare Metal / VM:

Kubernetes:

Common Issues

Issue
Solution

Logs not appearing

Ensure access_log path matches Fluent Bit Path. In K8s, ensure Nginx logs to /dev/stdout

Permission denied

Run Fluent Bit with appropriate permissions. In K8s, check RBAC and volume mounts

Connection refused

Verify network connectivity to stream.getlimy.ai. Check network policies in K8s

401 Unauthorized

Check that X-API-Key header value is correct

No logs in K8s

Verify the log path pattern matches your pod names. Check kubectl logs output directly

Startup messages in logs

Ensure the grep filter is configured to filter by log_type


Log Fields Reference

Field
Description

timestamp

ISO 8601 timestamp

client_ip

Client IP address

client_port

Client port

remote_user

Authenticated username (Basic Auth)

request

Full request line

request_method

HTTP method (GET, POST, etc.)

request_uri

Request URI with query string

uri

Request URI without query string

args

Query string parameters

scheme

http or https

server_protocol

HTTP version

request_length

Request size in bytes

request_time

Request processing time (seconds)

status

HTTP response status code

body_bytes_sent

Response body size

bytes_sent

Total response size

host

Request host

server_addr

Server IP address

server_port

Server port

server_name

Server name from config

hostname

Machine hostname

http_user_agent

User-Agent header

http_referer

Referer header

http_x_forwarded_for

X-Forwarded-For header

upstream_*

Upstream/proxy metrics

ssl_*

TLS/SSL connection details

gzip_ratio

Compression ratio


Support

If you encounter any issues, please contact Limy support with:

  • Fluent Bit version (fluent-bit --version)

  • Nginx version (nginx -v)

  • Your deployment type (Bare Metal, Docker, or Kubernetes)

  • Relevant error logs

  • Your configuration files (with API key redacted)

Last updated