Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Rails3 and FastCGI

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 app
Octocat-spinner-32 config
Octocat-spinner-32 db
Octocat-spinner-32 doc
Octocat-spinner-32 lib
Octocat-spinner-32 public
Octocat-spinner-32 script
Octocat-spinner-32 test
Octocat-spinner-32 vendor
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Capfile
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 config.ru
README.markdown

Rails3-FastCGI

Simple Rails3 application configured to be deployed on apache2 with fastCGI and capistrano. You need to have FastCGI library for Ruby and FastCGI module for apache2 installed.

Files of interest:

Apache2 site configuration


  DefaultInitEnv RAILS_ENV production
  DocumentRoot /home/krg/www/rails3_fcgi/current/public
  
    Options ExecCGI FollowSymLinks
    AllowOverride all
    Order allow,deny
    Allow from all
  

public/.htaccess

SetEnv RAILS_RELATIVE_URL_ROOT /rails3_fcgi

RewriteEngine On

RewriteRule ^(stylesheets/.*)$ - [L]
RewriteRule ^(javascripts/.*)$ - [L]
RewriteRule ^(images/.*)$ - [L]

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ rails3_fcgi.fcgi [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]

public/rails3_fcgi.fcgi

#!/usr/bin/ruby

require_relative '../config/environment'

class Rack::PathInfoRewriter
  def initialize(app)
    @app = app
  end

  def call(env)
    env.delete('SCRIPT_NAME')
    parts = env['REQUEST_URI'].split('?')
    env['PATH_INFO'] = parts[0]
    env['QUERY_STRING'] = parts[1].to_s
    @app.call(env)
  end
end

Rack::Handler::FastCGI.run  Rack::PathInfoRewriter.new(Rails3Fcgi::Application)

config/routes.rb

Rails3Fcgi::Application.routes.draw do
  my_draw = Proc.new do
    resources :entities
    root :to => "entities#index"
  end

  if ENV['RAILS_RELATIVE_URL_ROOT']
    scope ENV['RAILS_RELATIVE_URL_ROOT'] do
      my_draw.call
    end
  else
    my_draw.call
  end
end

config/deploy.rb

set :application, "rails3_fcgi"
set :user,        "krg"  # The server's user for deploys
set :domain,      "#{application}.lan"
set :repository,  "git@github.com:dre3k/#{application}.git"
set :deploy_to,   "/home/#{user}/www/#{application}"

set :scm, :git

role :web, domain  # Your HTTP server, Apache/etc
role :app, domain  # This may be the same as your `Web` server
role :db, domain, :primary => true  # This is where Rails migrations will run

default_run_options[:pty] = true
set :use_sudo, false
ssh_options[:forward_agent] = true
set :brach, "master"
set :deploy_via, :remote_cache
set :scm_verbose, true

deploy.task :db_link do
  run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
  run "ln -nfs #{shared_path}/db/production.sqlite3 #{release_path}/db/production.sqlite3"
  run "chmod 0777 #{release_path}/db"
end
after "deploy:update_code", "deploy:db_link"

namespace :deploy do
  task :restart do
    run "#{sudo} killall #{application}.fcgi"
    run "wget #{domain} --spider -O  -"
  end
end
Something went wrong with that request. Please try again.