Nginx Reverse Proxy: How to disable writing to access_log and error_log on CentOS Linux System

Nginx (known as Engine X) is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server, originally written by Igor Sysoev. There are many top websites that are using Nginx as an HTTP server and also millions of websites use Nginx as a reverse proxy to accelerate the delivery of static contents.Nginx: How to disable writing to access_log and error_log on CentOS Linux System

On my server, I have installed Nginx as a reverse proxy, so the instructions are applicable only for Nginx reverse proxy. I am not sure if it will work for Nginx HTTP server. By default, Nginx reverse proxy generates accees_log and error_log and these files are created every day for each and every access and error. If you have installed Nginx reverse proxy for a website that gets huge traffic, you might run out of disk space in a few days or months. So, to avoid the disk space issue, you should disable writing to access_log and error_log. If you can keep adding extra disks, you should not worry about it. However, I observed that disabling access_log and error_log improves the server response by a few milliseconds.

Here are the steps to disable writing to access_log and error_log on CentOS system. I have not tested on any other Linux system.

  1. Open /etc/nginx/nginx.conf and enter the followings under http:

http {
	  access_log off;
	  error_log off;
   }

If it does not work, try the following

http {       
	access_log /dev/null;
	error_log /dev/null;
}       

2. Open all .conf files under folder /etc/nginx/conf.d and comment out the access_log and error_log.

#access_log /var/log/nginx/access.a.b.c.d.log;
#error_log /var/log/nginx/error.a.b.c.d.log;     

3. Restart Nginx reverse proxy and Apache server.

4. SSH to your server and run the following command to see if the disabling worked.

find / -type f -name "*.log"

Image Credit: nginx.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.