Setting up nginx/passenger and logrotate on Ubuntu

We recently set up a fresh AWS Ubuntu instance running Ruby on Rails on Nginx and Passenger, and I wanted to make sure the nginx log files were included in the server’s lograte.  To do this, I needed to do the following.

With a default nginx configuration, you can configure the log directory to point to /var/logs directory.  I did this by running the following in the /opt/nginx directory:

ln -s /var/log logs

Then you’ll need to set up your logrotate.conf file to look for the nginx logs.  Edit the conf file with:

sudo nano /etc/logrotate.conf

then make your logrotate.conf file look like this

# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp — we’ll rotate them here
/var/log/wtmp {
missingok
monthly
create 0664 root utmp
rotate 1
}

/var/log/btmp {
missingok
monthly
create 0660 root utmp
rotate 1
}

/var/log/nginx_*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}

Comments are closed.