Search code examples
nginx

log_format in nginx.conf being ignored


Total NGINX beginner here.

My logs currently look like:

92.21.236.47 - - [08/Jan/2017:00:48:10 +0000] "GET / HTTP/1.1" 200 148 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0"

When I add the following line in the default /etc/nginx/nginx.conf

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

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

(the access_log and error_log lines already exist in the default config, I have put these here solely for context).

I then restart NGINX with:

systemctl restart nginx

I now expect my logs to change and in particular to show the xxx literal values used .. xxx[$time_local]xxx .. but my change makes no difference.

If I change log_format main to log_format combined then the server won't restart.


Solution

  • 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"';