Build Your Apache logs by Unified Log rotate cycle In EC2 Instances.
Log rotate by default configured in one of the EC2 instances for apache web server's access_log & error_log
Step:1
The below configuration was Actual entry (/etc/httpd/conf.d/example.com.conf)
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/vhosts/example.com/httpdocs/public_html/public
#CustomLog /var/www/vhosts/example.com/statistics/logs/access_log combined
#CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_log.%Y.%m.%d 86400" combined
CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_%d.%m.%Y.log 86400" combined
ErrorLog /var/www/vhosts/example.com/statistics/logs/error_log
<Directory /var/www/vhosts/example.com/httpdocs/public_html/public>
Options -Includes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/vhosts/example.com/httpdocs/public_html/public
CustomLog "|/usr/sbin/rotatelogs /var/www/vhosts/example.com/statistics/logs/access_ssl_%d.%m.%Y.log 86400" combined
ErrorLog /var/www/vhosts/example.com/statistics/logs/error_ssl_log
SSLEngine ON
SSLCACertificateFile /etc/pki/tls/certs/example.com-ca.crt
SSLCertificateKeyFile /etc/pki/tls/private/example.com.key
SSLCertificateFile /etc/pki/tls/certs/example.com.crt
<Directory /var/www/vhosts/example.com/httpdocs/public_html/public>
Options -Includes +FollowSymLinks +MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Step:2
The entry you might rotate every 7 days based on your requirement you will have to change accordingly.
This entry has to be done in the file path
File: /etc/logrotate.d/vhostlogs
##########################################################################################
/var/www/vhosts/example.com/statistics/logs/*.log {
daily
rotate 2
missingok
notifempty
nocreate
compress
postrotate
find /var/www/vhosts/example.com/statistics/logs/ -name "*.gz" -mtime +7 -delete
endscript
}
###########################################################################################
That's it you have done the Log rotate entry for Apache access logs!!!