sudo apt-get install -y awscli
sudo logrotate -d -f /etc/logrotate.d/nginx
sudo logrotate -f /etc/logrotate.d/nginx
| # sudo vi /etc/logrotate.d/nginx | |
| /var/log/nginx/logs/*.log { | |
| su root adm | |
| daily | |
| missingok | |
| rotate 10 | |
| compress | |
| delaycompress | |
| notifempty | |
| sharedscripts | |
| postrotate | |
| [ ! -f /var/log/nginx/logs/nginx.pid ] || kill -USR1 `cat /var/log/nginx/logs/nginx.pid` | |
| BUCKET=your_s3_bucket_name | |
| PUBLIC_IP=`curl --silent http://169.254.169.254/latest/meta-data/public-ipv4` | |
| gzip -c /var/log/nginx/logs/access.log.1 > /tmp/access.log.gz | |
| aws s3 cp /tmp/access.log.gz s3://$BUCKET/access_`date +%Y%m%dT%H%M%SZ`_$PUBLIC_IP.log.gz --region cn-north-1 | |
| endscript | |
| } |
Thanks. How about that using
$1variable instead ofaccess.log.1