Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Add traffic stat function to nginx. Useful for http accounting based on nginx configuration logic ( server / location / or anything else).
C C++
Failed to load latest commit information.
src Zero upstream_latency total when flushing
LICENSE add LICENSE file based on GPLv3 Update
config move utils to another project


Configure ngx_http_accounting_module as nginx module with --add-module when build nginx.

cd /path/to/nginx-src/

git clone -b v0.3

./configure --add-module=ngx_http_accounting_module

make && make install


Edit your nginx.conf.


    http_accounting  on;   # turn on accounting function
    server {
        http_accounting_id  accounting_id_str;   # set accounting_id based on server
        location / {
            http_accounting_id  accounting_id_str;    # set accounting_id based on location


This module write statistics to syslog. You should edit your syslog configuration.

For sample configuration / utils, see: Lax/ngx_http_accounting_module-utils

Sample syslog output

Apr  8 11:19:46 localhost NgxAccounting: pid:8555|from:1428463159|to:1428463186|accounting_id:default|requests:10|bytes_in:1400|bytes_out:223062|latency_ms:1873|upstream_latency_ms:1873|200:9|302:1

The output contains a list of k/v for the accounting metrics, in the sequence of:

key meaning
pid pid of nginx worker process
from / to metric was collected between these timestamps
accounting_id identify for the accounting unit, you name it with http_accounting_id directive
requests count of total requests processed
bytes_in total bytes receiverd by the server
bytes_out total bytes send out by the server
latency_ms average $request_time, in millisecond
upstream_latency_ms average $upstream_response_time, in millisecond
200 / 302 / 400 / 404 / 500 ... count of requests which response is with http code 200/302/400/404/500, etc


  • master : new feathers
  • v2-freeze-20110526 : works with nginx version(0.7.xx, 0.8.xx), nginx 0.9 is not tested. didn't work with nginx above 1.0.x.


Liu Lantao Github



Something went wrong with that request. Please try again.