Logrotate Nginx Custom Logs

As you know, when you create a site in nginx webserver, you will want to add custom logs for that site. So this post is a small tip to help you how to do it perfectly.

In your nginx site config (e.g /etx/nginx/site-availables/example.com), you add custom logs as below:

So now, your log files will be bigger day by day. You will have to remember to delete the log files if you do not want to your hard disk be full. What should you do now? Fortunately, Logrotate will help you compress. clean and backup it daily.

You just have to add (append) the content below to /etc/logrotate.d/nginx:

Finaly, run the command below to force the update.

It is done.