Setting up Nesta CMS with Capistrano and nginx

Nesta Setup

I already had Passenger and nginx set up on my Linode. I'll assume that git is already installed and that the user is familiarized with its use.

Follow the very simple instructions here to set up a local installation of Nesta. Create a new remote git repository and push over your new nesta code.

In the top of your new nesta directory, install the capistrano gem, run capify and manually edit your deploy.rb. I used the config/deploy.rb file I found here as a reference. Mine looks like this:

default_run_options[:pty] = true
ssh_options[:forward_agent] = true

set :domain, ""
set :application, ""
set :deploy_to, "/var/www/"

set :user, "scott"
set :use_sudo, false

set :scm, "git"
set :repository,  ""
set :branch, 'master'
set :git_shallow_clone, 1

role :web, domain
role :app, domain
role :db,  domain, :primary => true

set :deploy_via, :remote_cache

namespace :deploy do
  task :start do ; end
  task :stop do ; end
  # Assumes you are using Passenger
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"

  task :finalize_update, :except => { :no_release => true } do
    run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)

    # mkdir -p is making sure that the directories are there for some SCM's that don't save empty folders
    run <<-CMD
      rm -rf #{latest_release}/log &&
      mkdir -p #{latest_release}/public &&
      mkdir -p #{latest_release}/tmp &&
      ln -s #{shared_path}/log #{latest_release}/log

    if fetch(:normalize_asset_timestamps, true)
      stamp ="%Y%m%d%H%M.%S")
      asset_paths = %w(images css).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
      run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }

At this point I had to make sure my ssh public keys on all of my machines could authenticate to one another.

Now just run cap deploy and hopefully the script will pull your nesta code from your git repository and place it in the correct location on your production server.

I use sites-available and sites-enabled to manage nginx configuration for various sites hosted on this box. Here is my sites-available file:

server {
        listen 80;
        access_log      /var/log/nginx/;
        error_log       /var/log/nginx/;
        root            /var/www/;
        passenger_enabled on;


The ease with which this post was written and deployed has already justified the slight learning curve involved in getting everything set up. I look forward to using and customizing Nesta in the future.

Published on