capistrano-recipes 0.5.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +1 -1
- data/README.rdoc +73 -6
- data/Rakefile +2 -27
- data/capistrano-recipes.gemspec +21 -44
- data/doc/god/god +1 -0
- data/doc/god/god.conf +102 -0
- data/doc/god/god.init +62 -0
- data/generators/app.god.erb +25 -0
- data/generators/nginx.conf.erb +207 -0
- data/generators/unicorn.rb.erb +62 -0
- data/lib/capistrano_recipes.rb +1 -1
- data/lib/helpers.rb +62 -2
- data/lib/recipes/application.rb +67 -0
- data/lib/recipes/bluepill.rb +53 -0
- data/lib/recipes/bundler.rb +14 -0
- data/lib/recipes/db.rb +65 -5
- data/lib/recipes/deploy.rb +86 -16
- data/lib/recipes/god.rb +125 -0
- data/lib/recipes/hooks.rb +14 -0
- data/lib/recipes/log.rb +4 -4
- data/lib/recipes/nginx.rb +52 -0
- data/lib/recipes/passenger.rb +6 -6
- data/lib/recipes/resque.rb +48 -0
- data/lib/recipes/sphinx.rb +38 -0
- data/lib/recipes/symlinks.rb +27 -0
- data/lib/recipes/unicorn.rb +82 -0
- data/lib/version.rb +3 -0
- metadata +71 -17
- data/VERSION.yml +0 -4
- data/lib/recipes/symlink.rb +0 -51
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -6,19 +6,53 @@ Useful Capistrano recipes including:
|
|
6
6
|
* Create standalone copy of database.yml in shared path (via prompts)
|
7
7
|
* Log rotation and tailing commands
|
8
8
|
* Restart and profile Phusion Passenger application server
|
9
|
+
* Configure, start/stop/restart Unicorn application server
|
10
|
+
* Send commands to God or Bluepill monitoring tools
|
11
|
+
* Send commands to Thinking Sphinx
|
9
12
|
|
10
13
|
==Included Tasks
|
11
14
|
|
12
15
|
* cap db:create_yaml
|
13
16
|
* cap db:mysql:setup
|
17
|
+
* cap db:mysql:dump
|
18
|
+
* cap db:mysql:fetch_dump
|
19
|
+
* cap db:mysql:restore
|
14
20
|
* cap log:rotate
|
15
21
|
* cap log:tail
|
16
22
|
* cap passenger:bounce
|
17
23
|
* cap passenger:memory
|
18
24
|
* cap passenger:status
|
19
|
-
* cap
|
20
|
-
* cap
|
21
|
-
* cap
|
25
|
+
* cap nginx:setup
|
26
|
+
* cap nginx:start
|
27
|
+
* cap nginx:stop
|
28
|
+
* cap nginx:restart
|
29
|
+
* cap nginx:status
|
30
|
+
* cap unicorn:start
|
31
|
+
* cap unicorn:stop
|
32
|
+
* cap unicorn:restart
|
33
|
+
* cap unicorn:setup
|
34
|
+
* cap symlinks:make
|
35
|
+
* cap god:setup
|
36
|
+
* cap god:implode
|
37
|
+
* cap god:restart
|
38
|
+
* cap god:reload
|
39
|
+
* cap god:status
|
40
|
+
* cap god:terminate
|
41
|
+
* cap god:start
|
42
|
+
* cap god:stop
|
43
|
+
* cap god:quit
|
44
|
+
* cap bluepill:install
|
45
|
+
* cap bluepill:init
|
46
|
+
* cap bluepill:start
|
47
|
+
* cap bluepill:restart
|
48
|
+
* cap bluepill:stop
|
49
|
+
* cap bluepill:status
|
50
|
+
* cap sphinx:config
|
51
|
+
* cap sphinx:start
|
52
|
+
* cap sphinx:stop
|
53
|
+
* cap sphinx:rebuild
|
54
|
+
* cap sphinx:index
|
55
|
+
* cap sphinx:symlinks
|
22
56
|
|
23
57
|
==Installation
|
24
58
|
|
@@ -35,20 +69,53 @@ Optionally install the Capistrano extensions gem to give you multistage support:
|
|
35
69
|
Install this gem:
|
36
70
|
|
37
71
|
sudo gem install capistrano-recipes --source=http://gemcutter.com
|
38
|
-
|
72
|
+
|
39
73
|
To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
|
40
74
|
|
41
75
|
capify .
|
42
76
|
|
77
|
+
==Configuration
|
78
|
+
|
43
79
|
Inside the newly created config/deploy.rb, add:
|
44
80
|
|
45
|
-
require 'capistrano_recipes'
|
46
81
|
require 'capistrano/ext/multistage' # only require if you've installed Cap ext gem
|
82
|
+
|
83
|
+
# This one should go at the end of your deploy.rb
|
84
|
+
require 'capistrano_recipes'
|
85
|
+
|
86
|
+
===RVM
|
87
|
+
|
88
|
+
RVM is enabled by default. You can disable it by setting :using_rvm to false, or leverage it
|
89
|
+
by setting your rvm_ruby_string to appropriate ones (default is ree)
|
90
|
+
|
91
|
+
If using_rvm is true, the rvm recipe will load rvm's own capistrano extensions so you don't
|
92
|
+
have to worry about it during deploy. Just make sure you have everything set up right, like
|
93
|
+
.rvmrc on project root and system-wide install on the servers.
|
94
|
+
|
95
|
+
See (http://rvm.beginrescueend.com/rvm/install) for more info.
|
96
|
+
|
97
|
+
===Nginx
|
98
|
+
|
99
|
+
If you're using nginx as your web server, set :web_server to :nginx and deploy:setup will
|
100
|
+
generate the appropriate configuration file for it based on your other variables, such as
|
101
|
+
:application_uses_ssl, etc.
|
102
|
+
|
103
|
+
===Passenger
|
47
104
|
|
48
105
|
If you're running Phusion Passenger (http://www.modrails.com) be sure you add this line to config/deploy.rb:
|
49
106
|
|
50
107
|
set :server, :passenger
|
108
|
+
|
109
|
+
===Unicorn
|
110
|
+
|
111
|
+
If you're running Unicorn (http://unicorn.bogomips.org/) be sure to add this line instead:
|
112
|
+
|
113
|
+
set :server, :unicorn
|
114
|
+
|
115
|
+
==Contributors (thank you!)
|
116
|
+
|
117
|
+
* Leonardob Bighetti
|
51
118
|
|
52
119
|
==Copyright
|
53
120
|
|
54
|
-
Copyright (c) 2009 Webficient LLC, Phil Misiowiec. See LICENSE for details.
|
121
|
+
Copyright (c) 2009-2011 Webficient LLC, Phil Misiowiec. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,27 +1,2 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "capistrano-recipes"
|
8
|
-
gem.summary = %Q{Capistrano recipes}
|
9
|
-
gem.description = 'Extend the Capistrano gem with these useful recipes'
|
10
|
-
gem.email = "phil@webficient.com"
|
11
|
-
gem.homepage = "http://github.com/webficient/capistrano-recipes"
|
12
|
-
gem.authors = ["Phil Misiowiec"]
|
13
|
-
gem.add_dependency('capistrano', ['>= 2.5.9'])
|
14
|
-
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
-
end
|
16
|
-
rescue LoadError
|
17
|
-
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
18
|
-
end
|
19
|
-
|
20
|
-
require 'rake/rdoctask'
|
21
|
-
Rake::RDocTask.new do |rdoc|
|
22
|
-
rdoc.rdoc_dir = 'rdoc'
|
23
|
-
rdoc.title = 'capistrano-recipes'
|
24
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
25
|
-
rdoc.rdoc_files.include('README*')
|
26
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
27
|
-
end
|
1
|
+
require 'bundler/setup'
|
2
|
+
Bundler::GemHelper.install_tasks
|
data/capistrano-recipes.gemspec
CHANGED
@@ -1,52 +1,29 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
9
|
-
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
6
|
+
s.name = "capistrano-recipes"
|
7
|
+
s.version = CapistranoRecipes::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Phil Misiowiec", "Leonardo Bighetti"]
|
10
|
+
s.email = ["github@webficient.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Capistrano recipes}
|
13
13
|
s.description = %q{Extend the Capistrano gem with these useful recipes}
|
14
|
-
|
14
|
+
|
15
|
+
s.required_rubygems_version = ">= 1.3.6"
|
16
|
+
s.rubyforge_project = "capistrano-recipes"
|
17
|
+
|
18
|
+
s.files = `git ls-files`.split("\n")
|
19
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
20
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
21
|
+
s.require_paths = ["lib"]
|
15
22
|
s.extra_rdoc_files = [
|
16
23
|
"LICENSE",
|
17
24
|
"README.rdoc"
|
18
25
|
]
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION.yml",
|
25
|
-
"capistrano-recipes.gemspec",
|
26
|
-
"lib/capistrano_recipes.rb",
|
27
|
-
"lib/helpers.rb",
|
28
|
-
"lib/recipes/db.rb",
|
29
|
-
"lib/recipes/deploy.rb",
|
30
|
-
"lib/recipes/log.rb",
|
31
|
-
"lib/recipes/passenger.rb",
|
32
|
-
"lib/recipes/symlink.rb"
|
33
|
-
]
|
34
|
-
s.homepage = %q{http://github.com/webficient/capistrano-recipes}
|
35
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
-
s.require_paths = ["lib"]
|
37
|
-
s.rubygems_version = %q{1.3.5}
|
38
|
-
s.summary = %q{Capistrano recipes}
|
39
|
-
|
40
|
-
if s.respond_to? :specification_version then
|
41
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
42
|
-
s.specification_version = 3
|
43
|
-
|
44
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
45
|
-
s.add_runtime_dependency(%q<capistrano>, [">= 2.5.9"])
|
46
|
-
else
|
47
|
-
s.add_dependency(%q<capistrano>, [">= 2.5.9"])
|
48
|
-
end
|
49
|
-
else
|
50
|
-
s.add_dependency(%q<capistrano>, [">= 2.5.9"])
|
51
|
-
end
|
52
|
-
end
|
26
|
+
|
27
|
+
s.add_dependency "capistrano", ">= 2.5.9"
|
28
|
+
s.add_dependency "capistrano-ext", ">= 1.2.1"
|
29
|
+
end
|
data/doc/god/god
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
GOD_CONFIG=/etc/god/god.conf
|
data/doc/god/god.conf
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
APPS_ROOT = Dir.glob("/var/www/apps/*/current/config/app.god")
|
2
|
+
|
3
|
+
# Helper Methods
|
4
|
+
def unicorn(w, config, options = {})
|
5
|
+
rails_root = options[:rails_root]
|
6
|
+
rails_env = options[:rails_env] || 'production'
|
7
|
+
unicorn_group = options[:app] || options[:name] || 'default'
|
8
|
+
unicorn_name = "#{unicorn_group}-unicorn"
|
9
|
+
unicorn_bin = options[:bin_unicorn] || 'bootup_unicorn_rails'
|
10
|
+
unicorn_pid = options[:unicorn_pid] || "#{rails_root}/log/unicorn.pid"
|
11
|
+
unicorn_config = "#{rails_root}/config/unicorn.rb"
|
12
|
+
unicorn_start = options[:start_cmd] || "cd #{rails_root} && #{unicorn_bin} -c #{unicorn_config} -E #{rails_env} -D"
|
13
|
+
# QUIT gracefully shuts down workers
|
14
|
+
unicorn_stop = options[:stop_cmd] || "kill -QUIT `cat #{unicorn_pid}`"
|
15
|
+
# USR2 causes the master to re-create itself and spawn a new worker pool
|
16
|
+
unicorn_restart = options[:restart_cmd] || "kill -USR2 `cat #{unicorn_pid}`"
|
17
|
+
|
18
|
+
|
19
|
+
w.name = unicorn_name
|
20
|
+
w.group = unicorn_group
|
21
|
+
w.start = unicorn_start
|
22
|
+
w.stop = unicorn_stop
|
23
|
+
w.restart = unicorn_restart
|
24
|
+
w.start_grace = 20.seconds
|
25
|
+
w.restart_grace = 20.seconds
|
26
|
+
w.pid_file = unicorn_pid
|
27
|
+
w.behavior(:clean_pid_file)
|
28
|
+
|
29
|
+
generic_monitor(w, config, rails_root, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def generic_monitor(w, config, rails_root, options = {})
|
33
|
+
w.uid = options[:user] || 'deploy'
|
34
|
+
w.gid = options[:group] || 'www-data'
|
35
|
+
w.interval = 60.seconds # default
|
36
|
+
|
37
|
+
# determine the state on startup
|
38
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
39
|
+
on.condition(:process_running) do |c|
|
40
|
+
c.running = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# determine when process has finished starting
|
45
|
+
w.transition([:start, :restart], :up) do |on|
|
46
|
+
on.condition(:process_running) do |c|
|
47
|
+
c.running = true
|
48
|
+
end
|
49
|
+
|
50
|
+
# failsafe
|
51
|
+
on.condition(:tries) do |c|
|
52
|
+
c.times = 5
|
53
|
+
c.transition = :start
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# start if process is not running
|
58
|
+
w.transition(:up, :start) do |on|
|
59
|
+
on.condition(:process_exits) do |c|
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# restart if memory or cpu is too high
|
64
|
+
w.transition(:up, :restart) do |on|
|
65
|
+
on.condition(:memory_usage) do |c|
|
66
|
+
c.interval = 20
|
67
|
+
c.above = options[:memory_limit] || 150.megabytes
|
68
|
+
c.times = [3, 5]
|
69
|
+
end
|
70
|
+
|
71
|
+
on.condition(:cpu_usage) do |c|
|
72
|
+
c.interval = 20
|
73
|
+
c.above = options[:cpu_limit] || 50.percent
|
74
|
+
c.times = [3, 5]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# lifecycle
|
79
|
+
w.lifecycle do |on|
|
80
|
+
on.condition(:flapping) do |c|
|
81
|
+
c.to_state = [:start, :restart]
|
82
|
+
c.times = 5
|
83
|
+
c.within = 5.minute
|
84
|
+
c.transition = :unmonitored
|
85
|
+
c.retry_in = 10.minutes
|
86
|
+
c.retry_times = 5
|
87
|
+
c.retry_within = 2.hours
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
God.log_level = :info
|
93
|
+
puts "God is loading the apps now..."
|
94
|
+
APPS_ROOT.each do |app|
|
95
|
+
begin
|
96
|
+
puts "Loading app: #{app}"
|
97
|
+
God.load app
|
98
|
+
puts "Done"
|
99
|
+
rescue Exception => e
|
100
|
+
puts "Failed! #{e}"
|
101
|
+
end
|
102
|
+
end
|
data/doc/god/god.init
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
### BEGIN INIT INFO
|
4
|
+
# Provides: god
|
5
|
+
# Required-Start: $all
|
6
|
+
# Required-Stop: $all
|
7
|
+
# Default-Start: 2 3 4 5
|
8
|
+
# Default-Stop: 0 1 6
|
9
|
+
# Short-Description: God
|
10
|
+
### END INIT INFO
|
11
|
+
|
12
|
+
NAME=god
|
13
|
+
DESC=god
|
14
|
+
|
15
|
+
GOD_BIN=/usr/local/bin/bootup_god
|
16
|
+
GOD_PID=/var/run/god.pid
|
17
|
+
GOD_LOG=/var/log/god.log
|
18
|
+
set -e
|
19
|
+
|
20
|
+
# Make sure the binary and the config file are present before proceeding
|
21
|
+
test -x $GOD_BIN || exit 0
|
22
|
+
|
23
|
+
# Create this file and put in a variable called GOD_CONFIG, pointing to
|
24
|
+
# your God configuration file
|
25
|
+
test -f /etc/default/god && . /etc/default/god
|
26
|
+
[ $GOD_CONFIG ] || exit 0
|
27
|
+
|
28
|
+
. /lib/lsb/init-functions
|
29
|
+
|
30
|
+
RETVAL=0
|
31
|
+
|
32
|
+
case "$1" in
|
33
|
+
start)
|
34
|
+
echo -n "Starting $DESC: "
|
35
|
+
$GOD_BIN -c $GOD_CONFIG -P $GOD_PID -l $GOD_LOG
|
36
|
+
RETVAL=$?
|
37
|
+
echo "$NAME."
|
38
|
+
;;
|
39
|
+
stop)
|
40
|
+
echo -n "Stopping $DESC: "
|
41
|
+
kill `cat $GOD_PID`
|
42
|
+
RETVAL=$?
|
43
|
+
echo "$NAME."
|
44
|
+
;;
|
45
|
+
restart)
|
46
|
+
echo -n "Restarting $DESC: "
|
47
|
+
kill `cat $GOD_PID`
|
48
|
+
$GOD_BIN -c $GOD_CONFIG -P $GOD_PID -l $GOD_LOG
|
49
|
+
RETVAL=$?
|
50
|
+
echo "$NAME."
|
51
|
+
;;
|
52
|
+
status)
|
53
|
+
$GOD_BIN status
|
54
|
+
RETVAL=$?
|
55
|
+
;;
|
56
|
+
*)
|
57
|
+
echo "Usage: god {start|stop|restart|status}"
|
58
|
+
exit 1
|
59
|
+
;;
|
60
|
+
esac
|
61
|
+
|
62
|
+
exit $RETVAL
|
@@ -0,0 +1,25 @@
|
|
1
|
+
app_name = '<%= application %>'
|
2
|
+
rails_root = '<%= deploy_to %>/current'
|
3
|
+
unicorn_bin = '<%= unicorn_bin %>'
|
4
|
+
unicorn_pid = '<%= unicorn_pid %>'
|
5
|
+
unicorn_config = '<%= unicorn_remote_config %>'
|
6
|
+
unicorn_start_cmd = '<%= unicorn_start_cmd %>'
|
7
|
+
unicorn_stop_cmd = '<%= unicorn_stop_cmd %>'
|
8
|
+
unicorn_restart_cmd = '<%= unicorn_restart_cmd %>'
|
9
|
+
|
10
|
+
# Unicorn
|
11
|
+
God.watch do |w|
|
12
|
+
unicorn(w, rails_root,
|
13
|
+
:memory_limit => 100.megabytes,
|
14
|
+
:cpu_limit => 50.percent,
|
15
|
+
:bin_unicorn => unicorn_bin,
|
16
|
+
:name => app_name,
|
17
|
+
:rails_root => rails_root,
|
18
|
+
:unicorn_conf => unicorn_config,
|
19
|
+
:unicorn_pid => unicorn_pid,
|
20
|
+
:start_cmd => unicorn_start_cmd,
|
21
|
+
:stop_cmd => unicorn_stop_cmd,
|
22
|
+
:restart_cmd => unicorn_restart_cmd,
|
23
|
+
:user => '<%= unicorn_user %>',
|
24
|
+
:group => '<%= unicorn_group %>')
|
25
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
<% if is_using_unicorn %>
|
2
|
+
upstream <%= application %>_app_server {
|
3
|
+
server unix:<%= unicorn_socket %> fail_timeout=0;
|
4
|
+
}
|
5
|
+
<% end %>
|
6
|
+
# <%= application %> Server
|
7
|
+
server {
|
8
|
+
listen <%= application_port %>;
|
9
|
+
<% if is_using_passenger %>
|
10
|
+
rails_env <%= rails_env %>;
|
11
|
+
passenger_enabled on;
|
12
|
+
<% end %>
|
13
|
+
client_max_body_size 500M;
|
14
|
+
server_name <%= application %>;
|
15
|
+
|
16
|
+
# ~2 seconds is often enough for most folks to parse HTML/CSS and
|
17
|
+
# retrieve needed images/icons/frames, connections are cheap in
|
18
|
+
# nginx so increasing this is generally safe...
|
19
|
+
keepalive_timeout 5;
|
20
|
+
|
21
|
+
# path for static files
|
22
|
+
root <%= deploy_to %>/current/public;
|
23
|
+
access_log <%= deploy_to %>/current/log/nginx.access.log main;
|
24
|
+
error_log <%= deploy_to %>/current/log/nginx.error.log info;
|
25
|
+
|
26
|
+
# this rewrites all the requests to the maintenance.html
|
27
|
+
# page if it exists in the doc root. This is for capistrano's
|
28
|
+
# disable web task
|
29
|
+
if (-f $document_root/system/maintenance.html) {
|
30
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
31
|
+
break;
|
32
|
+
}
|
33
|
+
|
34
|
+
location / {
|
35
|
+
<% if is_using_passenger %>
|
36
|
+
rails_env <%= rails_env %>;
|
37
|
+
passenger_enabled on;
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
41
|
+
proxy_set_header Host $http_host;
|
42
|
+
|
43
|
+
# If the file exists as a static file serve it directly without
|
44
|
+
# running all the other rewite tests on it
|
45
|
+
if (-f $request_filename) {
|
46
|
+
break;
|
47
|
+
}
|
48
|
+
|
49
|
+
# check for index.html for directory index
|
50
|
+
# if its there on the filesystem then rewite
|
51
|
+
# the url to add /index.html to the end of it
|
52
|
+
# and then break to send it to the next config rules.
|
53
|
+
if (-f $request_filename/index.html) {
|
54
|
+
rewrite (.*) $1/index.html break;
|
55
|
+
}
|
56
|
+
|
57
|
+
# this is the meat of the rails page caching config
|
58
|
+
# it adds .html to the end of the url and then checks
|
59
|
+
# the filesystem for that file. If it exists, then we
|
60
|
+
# rewite the url to have explicit .html on the end
|
61
|
+
# and then send it on its way to the next config rule.
|
62
|
+
# if there is no file on the fs then it sets all the
|
63
|
+
# necessary headers and proxies to our upstream mongrels
|
64
|
+
if (-f $request_filename.html) {
|
65
|
+
rewrite (.*) $1.html break;
|
66
|
+
}
|
67
|
+
|
68
|
+
<% if is_using_unicorn %>
|
69
|
+
if (!-f $request_filename) {
|
70
|
+
proxy_pass http://<%= application %>_app_server;
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
<% end %>
|
74
|
+
}
|
75
|
+
|
76
|
+
# Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
|
77
|
+
# BUT there's a chance it could break the ajax calls.
|
78
|
+
location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
|
79
|
+
expires max;
|
80
|
+
break;
|
81
|
+
}
|
82
|
+
|
83
|
+
location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
|
84
|
+
expires max;
|
85
|
+
break;
|
86
|
+
}
|
87
|
+
|
88
|
+
# Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
|
89
|
+
# BUT there's a chance it could break the ajax calls.
|
90
|
+
location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
|
91
|
+
expires max;
|
92
|
+
break;
|
93
|
+
}
|
94
|
+
|
95
|
+
location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
|
96
|
+
expires max;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
|
100
|
+
# if the request is for a static resource, nginx should serve it directly
|
101
|
+
# and add a far future expires header to it, making the browser
|
102
|
+
# cache the resource and navigate faster over the website
|
103
|
+
location ~ ^/(images|javascripts|stylesheets|system)/ {
|
104
|
+
root /home/deployer/shop/current/public;
|
105
|
+
expires max;
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
|
109
|
+
# Rails error pages
|
110
|
+
error_page 500 502 503 504 /500.html;
|
111
|
+
location = /500.html {
|
112
|
+
root <%= deploy_to %>/current/public;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
<% if application_uses_ssl %>
|
117
|
+
|
118
|
+
<% if is_using_unicorn %>
|
119
|
+
upstream <%= application %>_app_ssl {
|
120
|
+
server unix:<%= unicorn_socket %> fail_timeout=0;
|
121
|
+
}
|
122
|
+
<% end %>
|
123
|
+
|
124
|
+
# This server is setup for ssl. Uncomment if
|
125
|
+
# you are using ssl as well as port 80.
|
126
|
+
server {
|
127
|
+
listen <%= application_port_ssl%>;
|
128
|
+
server_name <%= application %>;
|
129
|
+
<% if is_using_passenger %>
|
130
|
+
rails_env <%= rails_env %>;
|
131
|
+
passenger_enabled on;
|
132
|
+
<% end %>
|
133
|
+
ssl on;
|
134
|
+
ssl_certificate /etc/ssl/certs/server.crt;
|
135
|
+
ssl_certificate_key /etc/ssl/private/server.key;
|
136
|
+
ssl_session_timeout 5m;
|
137
|
+
client_max_body_size 50M;
|
138
|
+
|
139
|
+
root <%= deploy_to %>/current/public;
|
140
|
+
access_log <%= deploy_to %>/current/log/nginx.access.log main;
|
141
|
+
error_log <%= deploy_to %>/current/log/nginx.error.log info;
|
142
|
+
|
143
|
+
# this rewrites all the requests to the maintenance.html
|
144
|
+
# page if it exists in the doc root. This is for capistrano's
|
145
|
+
# disable web task
|
146
|
+
if (-f $document_root/system/maintenance.html) {
|
147
|
+
rewrite ^(.*)$ /system/maintenance.html last;
|
148
|
+
break;
|
149
|
+
}
|
150
|
+
|
151
|
+
location / {
|
152
|
+
<% if is_using_passenger %>
|
153
|
+
rails_env <%= rails_env %>;
|
154
|
+
passenger_enabled on;
|
155
|
+
<% end %>
|
156
|
+
|
157
|
+
# needed to forward user's IP address to rails
|
158
|
+
proxy_set_header X-Real-IP $remote_addr;
|
159
|
+
|
160
|
+
# needed for HTTPS
|
161
|
+
proxy_set_header X_FORWARDED_PROTO https;
|
162
|
+
|
163
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
164
|
+
proxy_set_header Host $http_host;
|
165
|
+
proxy_redirect off;
|
166
|
+
proxy_max_temp_file_size 0;
|
167
|
+
|
168
|
+
|
169
|
+
# If the file exists as a static file serve it directly without
|
170
|
+
# running all the other rewite tests on it
|
171
|
+
if (-f $request_filename) {
|
172
|
+
break;
|
173
|
+
}
|
174
|
+
|
175
|
+
# check for index.html for directory index
|
176
|
+
# if its there on the filesystem then rewite
|
177
|
+
# the url to add /index.html to the end of it
|
178
|
+
# and then break to send it to the next config rules.
|
179
|
+
if (-f $request_filename/index.html) {
|
180
|
+
rewrite (.*) $1/index.html break;
|
181
|
+
}
|
182
|
+
|
183
|
+
# this is the meat of the rails page caching config
|
184
|
+
# it adds .html to the end of the url and then checks
|
185
|
+
# the filesystem for that file. If it exists, then we
|
186
|
+
# rewite the url to have explicit .html on the end
|
187
|
+
# and then send it on its way to the next config rule.
|
188
|
+
# if there is no file on the fs then it sets all the
|
189
|
+
# necessary headers and proxies to our upstream mongrels
|
190
|
+
if (-f $request_filename.html) {
|
191
|
+
rewrite (.*) $1.html break;
|
192
|
+
}
|
193
|
+
|
194
|
+
<% if is_using_unicorn %>
|
195
|
+
if (!-f $request_filename) {
|
196
|
+
proxy_pass http://<%= application %>_app_ssl;
|
197
|
+
break;
|
198
|
+
}
|
199
|
+
<% end %>
|
200
|
+
}
|
201
|
+
|
202
|
+
error_page 500 502 503 504 /500.html;
|
203
|
+
location = /500.html {
|
204
|
+
root <%= deploy_to %>/current/public;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
<% end %>
|