Nginx – how set separate log file, to log 400 bad request errors in nginx

nginx

I have a nginx to host a django application. I need to log 400 Bad Request errors from my web page to a separate log file in nginx configuration.

The docs I found was to give separate response in case of errors. I tried the following code with nginx configuration:

error_page 400 /400.html;

location /400.html {
    internal;
}

But the above code does not log the 400 errors.

Best Answer

In your snipet missing definiton of error log.

error_page 400 /400.html;

location /400.html {
    internal;
    error_log logs/400.log error;
}

In case you need documentation http://nginx.org/en/docs/ngx_core_module.html#error_log