In order to have your cache always created with a group of www-data you need to do the following:
cd yourrailsapp
chgrp www-data ./tmp
sudo chmod g+s tmp
This sets the group id on your folder so that everything underneath tmp gets created with the correct permissions
References:
- https://mdreeling.wordpress.com/2012/06/16/permissions-of-tmp-and-cache-folder-in-rails-for-nginx-to-resolve-access-denied/
- http://stackoverflow.com/questions/8127849/rails-3-1-errnoeacces-permission-denied/12700438#12700438
- http://serverfault.com/questions/357108/what-permissions-should-my-website-files-folders-have-on-a-linux-webserver