Search code examples
nginxcapistrano

capistrano remove cache permission denied


I have a webserver (Nginx) on a raspberry pi and I use capistrano to deploy my website. I'm newbie with Capistrano, but I find it funny.

My problem is that when Capistrano want to remove an old release, it can't because Nginx has written in the cache directory with the user www-data and I have a error: permission denied!

How to fix it?

I hope that I am clear.


Solution

  • Generally speaking, you don't want your web server to write into the Capistrano releases. Otherwise you will run into this problem.

    I would suggest one of two workarounds:

    1. Change your Ngnix config so that it uses a different location for its cache. For example, /var/nginx/cache/app_name.
    2. If the cache location must be within the app, make that directory a "shared" directory in Capistrano. This will put a symlink in each release that points to a single shared directory in a separate location.

    For example, assuming the cache is written to a cache directory at the root of your release, you would tell Capistrano:

    set :linked_dirs, fetch(:linked_dirs, []) << "cache"