B
B
b4rret2016-06-22 16:31:51
Nginx
b4rret, 2016-06-22 16:31:51

How to change log format in nginx?

I change the log format as follows

server{
...
  log_format piwik '{"ip": "$remote_addr",'
                '"host": "$host",'
                '"path": "$request_uri",'
                '"status": "$status",'
                '"referrer": "$http_referer",'
                '"user_agent": "$http_user_agent",'
                '"length": $bytes_sent,'
                '"generation_time_milli": $request_time,'
                '"date": "$time_iso8601"}';

    access_log  /path/to/log/log_access.log piwik;
    error_log   /path/to/log/log_error.log piwik;
...
}

But upon reboot, nginx swears at the wrong config.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Lynn "Coffee Man", 2016-06-22
@b4rret

The error_log cannot be formatted.
log_format should be inside http, not server.

A
Andrey Shatokhin, 2016-06-22
@Sovigod

Move log_format to http context

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question