Setting up nginx logs

I will give examples of setting logging for nginx.

To change the log settings, open the nginx configuration file in any text editor:

sudo nano /etc/nginx/nginx.conf

Probably there will be entries:

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

For error logs, you can specify the level of recorded information (where instead of LEVEL we specify any of: emerg, alert, crit, error, warn, notice, info, debug):

error_log /var/log/nginx/error.log LEVEL;

For example, to increase the error logs to the debug level:

error_log /var/log/nginx/error.log debug;

In order not to write error logs, you can send them to /dev/null:

error_log /dev/null crit;

In order not to write access logs, simply indicate:

access_log off;

Access logs can be configured for any format, for example, write only the date and IP address:

log_format small '$remote_addr - $remote_user [$time_local]';
access_log /var/log/nginx/access.log small;

Or more detailed:

log_format myformat '$remote_addr - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
access_log /var/log/nginx/access.log myformat;

See also my article:
Install and configure Nginx

Leave a comment

Leave a Reply