log_format in nginx.conf being ignored

Its late to reply but it might be useful for those who are still hanging in this prolem.

Write the log_format directives outsider the server {}

The whole code would be like this

log_format main '$remote_addr - $remote_user xxx[$time_local]xxx '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent"';
server {
      listen 80;
      access_log /var/log/nginx/<your_domain>_access.log main; 
}

Here main represents what fields nginx should include while writing the logs.

For more detail information, Please look in the official documentation Sampling Requests with NGINX Conditional Logging


changing ..

access_log /var/log/nginx/access.log;

to ..

access_log /var/log/nginx/access.log main;

fixed it.

where main is the name of the log_format as defined at ..

log_format main '$remote_addr - $remote_user xxx[$time_local]xxx '
                '"$request" $status $body_bytes_sent '
                '"$http_referer" "$http_user_agent"';

2 above answers tried but didnt help. and i realized that

above the log_format line in my nginx.conf, server brace was not closed. and it gave me the same error.

Tags:

Nginx