Can I log HTTP 400s to a different log file instead of my default access logs

António P. P. Almeida appa at perusio.net
Mon Nov 7 12:04:22 UTC 2011


On 7 Nov 2011 11h38 WET, appa at perusio.net wrote:

> On 7 Nov 2011 11h21 WET, nginx-forum at nginx.us wrote:
>
>> Hello
>>
>> I'd like to know if its possible for me to log HTTP 400 errors to a
>> different log file. Right now they go in the access log. 
>>
>> To give some background, we've got this problem where if a single
>> resource is requested from chrome, after the resource request is
>> served, a http 400 error is logged in the access logs. This I've
>> understood to be is due to the nature of connections opened by
>> Chrome (2 for every request) and one of the connections not been
>> used before its closed. And nginx reports a 400 in this
>> instance. I've gathered this based on a different forum entry. And
>> when this 400 is logged, the $request_filename is /etc/nginx//html
>
> Try (untested):
>
> at the http level:
>
> map $request_filename $is_400 {
> default 0;
> /etc/nginx/html 1; 
> }

Oops. Solly I haven't my coffe yet :)

Try (untested):

at the http level:

map $request_filename $is_400 {
   default 0;
   /etc/nginx/html 1; 
}

On the vhost:

if ($is_400) {
  return 302 @log-400;
}

location @log-400 {
   access_log /path/to/400.log;
}

--- appa



More information about the nginx mailing list