How to disable NGINX logging on Linux

Disabling logging in NGINX can be useful for various reasons, such as reducing disk usage, improving performance, or simply because you don’t need the logs for a particular application. This guide will walk you through the steps to disable access and error logging in NGINX on a Linux system.

In this tutorial you will learn:

  • How to disable access logs in NGINX
  • How to disable error logs in NGINX
  • How to completely disable error logging in NGINX
How to disable NGINX logging on Linux
How to disable NGINX logging on Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Linux-based operating system
Software NGINX
Other Basic command-line knowledge
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to Disable NGINX Logging on Linux

Disabling NGINX logging involves modifying the NGINX configuration files. Below are detailed steps to disable access and error logging.

  1. Disable Access Logs: The first step is to disable access logs by modifying the NGINX configuration file.
    $ sudo nano /etc/nginx/nginx.conf

    In the configuration file, find the access_log directive and comment it out by adding a # at the beginning of the line or set it to off:

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

    Save the file and exit the editor.



  2. Disable Error Logs: The next step is to disable error logs in the same configuration file.
    $ sudo nano /etc/nginx/nginx.conf

    In the configuration file, find the error_log directive and comment it out by adding a # at the beginning of the line or set it to /dev/null:

    #error_log /var/log/nginx/error.log;
    error_log /dev/null crit;

    Setting the error log to /dev/null with the crit level means only critical errors will be logged, effectively minimizing the logging.

  3. Completely Disable Error Logging: If you want to completely disable error logging, you can set the error_log directive to /dev/null without specifying any log level.
    $ sudo nano /etc/nginx/nginx.conf

    In the configuration file, find the error_log directive and set it to /dev/null without any log level:

    error_log /dev/null;

    This configuration will completely disable error logging.

  4. Restart NGINX: After making changes to the configuration file, you need to restart NGINX to apply the changes.
    $ sudo systemctl restart nginx

    Restarting NGINX will apply the new settings, and logging will be disabled as specified.

Conclusion

Disabling logging in NGINX is a straightforward process that can help in optimizing system performance and managing disk space. By following the steps outlined above, you can easily disable both access and error logs in your NGINX server configuration.



Comments and Discussions
Linux Forum