How To Configure Logging and Log Rotation in Nginx on an Ubuntu VPS
How To Configure Logging and Log Rotation in Nginx on an Ubuntu VPS
In this tutorial, we will go through the steps to configure logging and log rotation in Nginx on an Ubuntu VPS. Logging is an essential part of any server, and it is necessary to keep track of server activities, debug errors and troubleshoot issues. Log rotation, on the other hand, ensures that log files do not grow too large and fill up the server's disk space.
Step 1: Enable Nginx Logging
The first step is to enable Nginx logging. Open the Nginx configuration file by running the following command:
sudo nano /etc/nginx/nginx.conf
Scroll down to the http block, and add the following lines:
http {
...
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
...
}
Save and close the file.
Step 2: Configure Log Rotation
The next step is to configure log rotation. Nginx comes with a logrotate configuration file that can be used for log rotation. Open the file by running the following command:
sudo nano /etc/logrotate.d/nginx
Add the following lines to the file:
/var/log/nginx/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
/etc/init.d/nginx reload > /dev/null
endscript
}
Комментарии
Отправить комментарий