capistrano-exts 1.0.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.
Files changed (48) hide show
  1. data/.gitignore +4 -0
  2. data/Gemfile +4 -0
  3. data/Guardfile +13 -0
  4. data/Rakefile +9 -0
  5. data/capistrano-exts.gemspec +35 -0
  6. data/examples/php_fpm/deploy/development.rb +121 -0
  7. data/examples/php_fpm/deploy/production.rb +121 -0
  8. data/examples/php_fpm/deploy/staging.rb +121 -0
  9. data/examples/php_fpm/deploy.rb +38 -0
  10. data/examples/rails_passenger/deploy/development.rb +121 -0
  11. data/examples/rails_passenger/deploy/production.rb +121 -0
  12. data/examples/rails_passenger/deploy/staging.rb +121 -0
  13. data/examples/rails_passenger/deploy.rb +38 -0
  14. data/examples/rails_reverse_proxy/deploy/development.rb +121 -0
  15. data/examples/rails_reverse_proxy/deploy/production.rb +121 -0
  16. data/examples/rails_reverse_proxy/deploy/staging.rb +121 -0
  17. data/examples/rails_reverse_proxy/deploy.rb +38 -0
  18. data/lib/capistrano-exts/core_ext/string/filters.rb +12 -0
  19. data/lib/capistrano-exts/core_ext.rb +10 -0
  20. data/lib/capistrano-exts/receipts/base.rb +22 -0
  21. data/lib/capistrano-exts/receipts/contao.rb +81 -0
  22. data/lib/capistrano-exts/receipts/functions.rb +55 -0
  23. data/lib/capistrano-exts/receipts/git.rb +37 -0
  24. data/lib/capistrano-exts/receipts/god.rb +30 -0
  25. data/lib/capistrano-exts/receipts/multistage.rb +90 -0
  26. data/lib/capistrano-exts/receipts/mysql.rb +214 -0
  27. data/lib/capistrano-exts/receipts/rails.rb +45 -0
  28. data/lib/capistrano-exts/receipts/servers/db_server.rb +19 -0
  29. data/lib/capistrano-exts/receipts/servers/web_server/apache.rb +55 -0
  30. data/lib/capistrano-exts/receipts/servers/web_server/nginx.rb +81 -0
  31. data/lib/capistrano-exts/receipts/servers/web_server.rb +112 -0
  32. data/lib/capistrano-exts/receipts/servers.rb +51 -0
  33. data/lib/capistrano-exts/receipts/unicorn.rb +27 -0
  34. data/lib/capistrano-exts/receipts.rb +17 -0
  35. data/lib/capistrano-exts/servers/utils/erb.rb +16 -0
  36. data/lib/capistrano-exts/servers/utils/variables.rb +25 -0
  37. data/lib/capistrano-exts/servers/web_server/nginx.rb +20 -0
  38. data/lib/capistrano-exts/servers/web_server.rb +69 -0
  39. data/lib/capistrano-exts/templates/multistage.rb +118 -0
  40. data/lib/capistrano-exts/templates/web_servers/nginx.conf.erb +95 -0
  41. data/lib/capistrano-exts/version.rb +12 -0
  42. data/lib/capistrano-exts.rb +14 -0
  43. data/spec/rendered_templates/nginx_php_fpm.conf +58 -0
  44. data/spec/requests/nginx_spec.rb +38 -0
  45. data/spec/servers/web_server/nginx_spec.rb +179 -0
  46. data/spec/spec_helper.rb +27 -0
  47. data/spec/support/factories.rb +1 -0
  48. metadata +220 -0
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ require 'capistrano'
4
+
5
+ # Verify that Capistrano is version 2
6
+ unless Capistrano::Configuration.respond_to?(:instance)
7
+ abort "This extension requires Capistrano 2"
8
+ end
9
+
10
+ Capistrano::Configuration.instance(:must_exist).load do
11
+ namespace :deploy do
12
+ namespace :server do
13
+ namespace :web_server do
14
+ namespace :nginx do
15
+
16
+ _cset :nginx_init_path, "/etc/init.d/nginx"
17
+
18
+ desc "[internal] Generate Nginx configuration"
19
+ task :generate_configuration do
20
+ web_server_mode = fetch :web_server_mode
21
+ nginx = Capistrano::Extensions::Server::Nginx.new web_server_mode
22
+
23
+ nginx.application = fetch :application
24
+ nginx.public_path = fetch :public_path
25
+ nginx.logs_path = fetch :logs_path
26
+ nginx.application_url = fetch :application_url
27
+
28
+ nginx.listen_port = fetch(:web_server_listen_port) if exists?(:web_server_listen_port)
29
+
30
+ if exists?(:web_server_auth_file)
31
+ nginx.authentification_file = fetch :web_server_auth_file
32
+ end
33
+
34
+ nginx.indexes = fetch(:web_server_indexes) if exists?(:web_server_indexes)
35
+
36
+ if exists?(:web_server_mod_rewrite)
37
+ nginx.mod_rewrite = fetch :web_server_mod_rewrite
38
+ end
39
+
40
+ if exists?(:php_fpm_host)
41
+ nginx.php_fpm_host = fetch :php_fpm_host
42
+ nginx.php_fpm_port = fetch :php_fpm_port
43
+ end
44
+
45
+ set :web_conf, nginx
46
+ set :web_conf_contents, nginx.render
47
+ end
48
+
49
+ desc "Start nginx web server"
50
+ task :start do
51
+ run <<-CMD
52
+ #{try_sudo} #{fetch :nginx_init_path} start
53
+ CMD
54
+ end
55
+
56
+ desc "Stop nginx web server"
57
+ task :stop do
58
+ run <<-CMD
59
+ #{try_sudo} #{fetch :nginx_init_path} stop
60
+ CMD
61
+ end
62
+
63
+ desc "Restart nginx web server"
64
+ task :restart do
65
+ run <<-CMD
66
+ #{try_sudo} #{nginx_init_path} restart
67
+ CMD
68
+ end
69
+
70
+ desc "Resload nginx web server"
71
+ task :reload do
72
+ run <<-CMD
73
+ #{try_sudo} #{nginx_init_path} reload
74
+ CMD
75
+ end
76
+
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,112 @@
1
+ # encoding: utf-8
2
+
3
+ require 'capistrano'
4
+ require 'digest/sha1'
5
+
6
+ # Require all specific web_server files
7
+ Dir["#{File.dirname(__FILE__)}/web_server/*.rb"].each {|f| require f}
8
+
9
+ # Verify that Capistrano is version 2
10
+ unless Capistrano::Configuration.respond_to?(:instance)
11
+ abort "This extension requires Capistrano 2"
12
+ end
13
+
14
+ Capistrano::Configuration.instance(:must_exist).load do
15
+ namespace :deploy do
16
+ namespace :server do
17
+ namespace :web_server do
18
+ desc "Setup web server"
19
+ task :setup, :roles => :web do
20
+ # Empty task, server preparation goes into callbacks
21
+ end
22
+
23
+ desc "[internal] Generate Web configuration"
24
+ task :generate_web_configuration do
25
+ if exists?(:web_server_app)
26
+ web_server_app = fetch :web_server_app
27
+
28
+ case web_server_app
29
+ when :nginx
30
+ find_and_execute_task 'deploy:server:web_server:nginx:generate_configuration'
31
+ when :apache
32
+ find_and_execute_task 'deploy:server:web_server:generate_apache_configuration'
33
+ else
34
+ abort "I don't know how to build '#{web_server_app}' configuration."
35
+ end
36
+ end
37
+ end
38
+
39
+ desc "[internal] Generate authentification"
40
+ task :generate_authentification do
41
+ if exists?(:web_server_auth_credentials)
42
+ web_server_auth_credentials = fetch :web_server_auth_credentials
43
+ contents = Array.new
44
+
45
+ web_server_auth_credentials.each do |credentials|
46
+ if credentials[:password].is_a?(Proc)
47
+ password = credentials[:password].call.crypt(gen_pass(8))
48
+ else
49
+ password = credentials[:password].crypt(gen_pass(8))
50
+ end
51
+ contents << "#{credentials[:user]}:#{password}"
52
+ end
53
+
54
+ set :web_server_auth_file_contents, contents.join("\n")
55
+ end
56
+ end
57
+
58
+ desc "[internal] Generate Apache configuration"
59
+ task :generate_apache_configuration do
60
+ # TODO: Write Apache config generator
61
+ end
62
+
63
+ desc "[internal] Write authentification file"
64
+ task :write_web_server_auth_file do
65
+ if exists?(:web_server_auth_file)
66
+ web_server_auth_file = fetch :web_server_auth_file
67
+ web_server_auth_file_contents = fetch :web_server_auth_file_contents
68
+ random_file = "/tmp/#{fetch :application}_#{Digest::SHA1.hexdigest web_server_auth_file_contents}"
69
+
70
+ run <<-CMD
71
+ #{try_sudo} mkdir -p #{File.dirname web_server_auth_file}
72
+ CMD
73
+
74
+ put web_server_auth_file_contents, random_file
75
+
76
+ run <<-CMD
77
+ #{try_sudo} mv #{random_file} #{web_server_auth_file}
78
+ CMD
79
+ end
80
+ end
81
+
82
+ desc "[internal] Write web configuration file"
83
+ task :write_web_conf_file do
84
+ if exists?(:web_conf_file)
85
+ web_conf_file = fetch :web_conf_file
86
+ random_file = "/tmp/#{fetch :application}_#{Digest::SHA1.hexdigest web_conf_contents}"
87
+
88
+ run <<-CMD
89
+ #{try_sudo} mkdir -p #{File.dirname web_conf_file}
90
+ CMD
91
+
92
+ put web_conf_contents, random_file
93
+
94
+ run <<-CMD
95
+ #{try_sudo} mv #{random_file} #{web_conf_file}
96
+ CMD
97
+ end
98
+ end
99
+
100
+ task :finish do
101
+ # Empty task for callbacks
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+ before "deploy:server:web_server:setup", "deploy:server:web_server:generate_web_configuration"
108
+ after "deploy:server:web_server:setup", "deploy:server:web_server:finish"
109
+ after "deploy:server:web_server:generate_web_configuration", "deploy:server:web_server:generate_authentification"
110
+ after "deploy:server:web_server:generate_web_configuration", "deploy:server:web_server:write_web_conf_file"
111
+ after "deploy:server:web_server:generate_authentification", "deploy:server:web_server:write_web_server_auth_file"
112
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+
3
+ # Requirements
4
+ require 'capistrano'
5
+ require 'capistrano-exts/receipts/base'
6
+ require 'capistrano-exts/receipts/mysql'
7
+ require 'capistrano-exts/receipts/servers/web_server'
8
+ require 'capistrano-exts/receipts/servers/db_server'
9
+
10
+ # Verify that Capistrano is version 2
11
+ unless Capistrano::Configuration.respond_to?(:instance)
12
+ abort "This extension requires Capistrano 2"
13
+ end
14
+
15
+ Capistrano::Configuration.instance(:must_exist).load do
16
+ namespace :deploy do
17
+ namespace :server do
18
+ namespace :setup do
19
+ desc "Prepare the server (database server, web server and folders)"
20
+ task :default do
21
+ # Empty task, server preparation goes into callbacks
22
+ end
23
+
24
+ task :folders, :roles => :app do
25
+ run <<-CMD
26
+ mkdir -p #{fetch :deploy_to} &&
27
+ mkdir -p #{fetch :deploy_to}/backups
28
+ CMD
29
+
30
+ if exists? :logs_path
31
+ run <<-CMD
32
+ mkdir -p #{fetch :logs_path}
33
+ CMD
34
+ end
35
+ end
36
+
37
+ task :finish do
38
+ # Empty task for callbacks
39
+ end
40
+
41
+ end
42
+ end
43
+ end
44
+
45
+ # Callbacks
46
+ before "deploy:server:setup", "deploy:server:setup:folders"
47
+ after "deploy:server:setup", "deploy:server:setup:finish"
48
+
49
+ after "deploy:server:setup:folders", "deploy:server:db_server:setup"
50
+ after "deploy:server:setup:folders", "deploy:server:web_server:setup"
51
+ end
@@ -0,0 +1,27 @@
1
+ namespace :unicorn do
2
+ desc "start unicorn"
3
+ task :start, :roles => :app, :except => {:no_release => true} do
4
+ run "cd #{current_path} && #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
5
+ end
6
+
7
+ desc "stop unicorn"
8
+ task :stop, :roles => :app, :except => {:no_release => true} do
9
+ run "#{try_sudo} kill `cat #{unicorn_pid}`"
10
+ end
11
+
12
+ desc "unicorn reload"
13
+ task :reload, :roles => :app, :except => {:no_release => true} do
14
+ run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
15
+ end
16
+
17
+ desc "graceful stop unicorn"
18
+ task :graceful_stop, :roles => :app, :except => {:no_release => true} do
19
+ run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
20
+ end
21
+
22
+ desc "restart unicorn"
23
+ task :restart, :roles => :app, :except => {:no_release => true} do
24
+ stop
25
+ start
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ require 'capistrano'
2
+ require 'capistrano-exts/receipts/functions'
3
+
4
+ # Verify that Capistrano is version 2
5
+ unless Capistrano::Configuration.respond_to?(:instance)
6
+ abort "This extension requires Capistrano 2"
7
+ end
8
+
9
+ Capistrano::Configuration.instance(:must_exist).load do
10
+ on :load do
11
+ if exists?(:capistrano_extensions)
12
+ capistrano_extensions.each do |receipt|
13
+ require "capistrano-exts/receipts/#{receipt.to_s}"
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'erb'
4
+
5
+ module Capistrano
6
+ module Extensions
7
+ module Erb
8
+ def render
9
+ sanity_check
10
+
11
+ erb_template = ::ERB.new(File.read(@template))
12
+ erb_template.result(binding).strip_empty_lines
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'erb'
4
+
5
+ module Capistrano
6
+ module Extensions
7
+ module Variables
8
+
9
+ # Instead of defining a whole lot of attr_accessor, let's be smart about
10
+ # templates, right ?
11
+ def method_missing(method, *args, &block)
12
+ if method =~ /(.+)=$/
13
+ # Method 1: works but the attr_accessor would be set on all instances
14
+ # Which is not good
15
+ #
16
+ # self.class.__send__(:attr_accessor, $1.to_sym)
17
+ # self.__send__(method, *args, &block)
18
+
19
+ # Method 2: Just set the instance variable, works better
20
+ self.send(:instance_variable_set, "@#{$1.to_sym}", *args)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module Capistrano
4
+ module Extensions
5
+ module Server
6
+ class Nginx < WebServer
7
+
8
+ AVAILABLE_MODES = [:rails_passenger, :rails_reverse_proxy, :php_fpm]
9
+ NGINX_TEMPLATE_PATH = ROOT_PATH + '/capistrano-exts/templates/web_servers/nginx.conf.erb'
10
+
11
+ def initialize(mode, template_path = NGINX_TEMPLATE_PATH)
12
+ raise ArgumentError, "The requested mode is not supported" unless AVAILABLE_MODES.include?(mode)
13
+ raise ArgumentError, "The template file is not found or not readable" unless File.exists?(template_path)
14
+ @mode = mode.to_sym
15
+ @template = template_path
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+
3
+ require 'capistrano-exts/servers/utils/erb'
4
+ require 'capistrano-exts/servers/utils/variables'
5
+
6
+ module Capistrano
7
+ module Extensions
8
+ module Server
9
+ class WebServer
10
+
11
+ include Erb
12
+ include Variables
13
+
14
+ protected
15
+ def authentification?
16
+ @authentification_file.present?
17
+ end
18
+
19
+ def reverse_proxy?
20
+ @mode == :rails_reverse_proxy
21
+ end
22
+
23
+ def mod_rewrite?
24
+ (
25
+ @mod_rewrite.present? and
26
+ @mod_rewrite == true
27
+ ) or
28
+ (
29
+ @mod_rewrite.blank?
30
+ )
31
+ end
32
+
33
+ def php_fpm?
34
+ @mode == :php_fpm
35
+ end
36
+
37
+ def passenger?
38
+ @mode == :rails_passenger
39
+ end
40
+
41
+ def php_build_with_force_cgi_redirect?
42
+ # required if PHP was built with --enable-force-cgi-redirect
43
+ @php_build_with_force_cgi_redirect.present? and @php_build_with_force_cgi_redirect == true
44
+ end
45
+
46
+ def sanity_check
47
+ [:application_url, :application].each do |var|
48
+ unless instance_variable_get("@#{var.to_s}")
49
+ raise ArgumentError, "#{var.to_s} is required, please define it."
50
+ end
51
+ end
52
+
53
+ if php_fpm?
54
+ [:php_fpm_host, :php_fpm_port, :public_path].each do |var|
55
+ unless instance_variable_get("@#{var.to_s}")
56
+ raise ArgumentError, "#{var.to_s} is required, please define it."
57
+ end
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ # Require all web servers
69
+ Dir["#{File.dirname __FILE__}/web_server/*.rb"].each { |f| require f }
@@ -0,0 +1,118 @@
1
+ # Here you can set the server which you would like to, each server
2
+ # each role can have multiple servers, each server defined as user@server.com:port
3
+ # => port can be omiped and it defaults to 22
4
+ role :web, 'root@nasreddine.com:22'
5
+ role :app, 'root@nasreddine.com:22'
6
+ role :db, 'root@nasreddine.com:22', primary: true
7
+
8
+ # The project's branch to use
9
+ # Uncomment and edit this if you're using git, for other SCM's please refer
10
+ # to capistrano's documentation
11
+ set :branch, "master"
12
+
13
+ # Use sudo ?
14
+ set :use_sudo, false
15
+
16
+ # Define deployments options
17
+ set :deploy_to, "/home/vhosts/#{application}"
18
+ set :deploy_via, :remote_cache
19
+ set :logs_path, "#{deploy_to}/logs"
20
+ set :public_path, -> { "#{current_path}/public" }
21
+
22
+ # Keep only the last 5 releases
23
+ set :keep_releases, 5
24
+
25
+ # Using RVM? Set this to the ruby version/gemset to use
26
+ set :rvm_ruby_string, "1.9.2"
27
+
28
+ # Mysql credentials
29
+ set :mysql_credentials_file, -> { "#{deploy_to}/.mysql_password"}
30
+ set :mysql_credentials_host_regex, /hostname: (.*)$/o
31
+ set :mysql_credentials_host_regex_match, 1
32
+ set :mysql_credentials_user_regex, /username: (.*)$/o
33
+ set :mysql_credentials_user_regex_match, 1
34
+ set :mysql_credentials_pass_regex, /password: (.*)$/o
35
+ set :mysql_credentials_pass_regex_match, 1
36
+ set :mysql_root_credentials_file, "/root/.mysql_password"
37
+ set :mysql_root_credentials_host_regex, /hostname: (.*)$/o
38
+ set :mysql_root_credentials_host_regex_match, 1
39
+ set :mysql_root_credentials_user_regex, /username: (.*)$/o
40
+ set :mysql_root_credentials_user_regex_match, 1
41
+ set :mysql_root_credentials_pass_regex, /password: (.*)$/o
42
+ set :mysql_root_credentials_pass_regex_match, 1
43
+
44
+ #############
45
+ # Web server
46
+ #
47
+
48
+ # Which web server to use?
49
+ # valid options: :nginx and :apache
50
+ set :web_server_app, :nginx
51
+
52
+ # Server specific configurations
53
+ # Uncomment as necessary, default option are as follow
54
+ # set :nginx_init_path, '/etc/init.d/nginx'
55
+ # set :apache_init_path, '/etc/init.d/apache2'
56
+
57
+ # Absolute path to this application's web server configuration
58
+ # This gem suppose that you are already including files from the folder you're placing
59
+ # the config file in, if not the application won't be up after deployment
60
+ set :web_conf_file, -> { "/etc/nginx/#{fetch(:stage).to_s}/#{fetch :application}.conf" }
61
+
62
+ # Which port does the server runs on ?
63
+ set :web_server_listen_port, 80
64
+
65
+ # What is the application url ?
66
+ # THis is used for Virtual Hosts
67
+ set :application_url, %w(example.com www.example.com)
68
+
69
+ # What are the names of the indexes
70
+ set :web_server_indexes, %w(index.php index.html)
71
+
72
+ # HTTP Basic Authentifications
73
+ # Uncomment this if you would like to add HTTP Basic authentifications,
74
+ #
75
+ # Change the 'web_server_auth_file' to the absolute path of the htpasswd file
76
+ # web_server_auth_credentials is an array of user/password hashes, you can use
77
+ # gen_pass(length) in a Proc to generate a new password as shown below
78
+ #
79
+ # set :web_server_auth_file, -> { "/etc/nginx/htpasswds/#{fetch :application}.crypt" }
80
+ # set :web_server_auth_credentials, [
81
+ # {user: 'user1', password: 'pass1'},
82
+ # {user: 'user2', password: -> { gen_pass(8) } },
83
+ # ]
84
+
85
+ # Enable mode rewrite ?
86
+ set :web_server_mod_rewrite, true
87
+
88
+ # Which server mode to operate on?
89
+ # Valid options:
90
+ #
91
+ # For Nginx:
92
+ # => :rails_reverse_proxy, :rails_passenger, :php_fpm
93
+ # => :rails_reverse_proxy is used for unicorn (Rack apps)
94
+ # => :rails_passenger runs rails apps
95
+ # => :php_fpm is used to deliver websites written using PHP
96
+ #
97
+ # For Apache
98
+ # =>
99
+ set :web_server_mode, :rails_reverse_proxy
100
+
101
+ # Server mode specific configurations
102
+ # Uncomment and edit the one depending on the enabled mode
103
+ # php_fpm settings
104
+ # => On which host, php-fpm is running ?
105
+ # set :php_fpm_host, 'localhost'
106
+ # => Which port ?
107
+ # set :php_fpm_port, '9000'
108
+
109
+ # reverse_proxy settings (Unicorn for example)
110
+ # => On which host the proxy is running ?
111
+ # set :reverse_proxy_server_address, 'localhost'
112
+ # => On which port ?
113
+ # set :reverse_proxy_server_port, 45410
114
+ # => What is the path to the socket file
115
+ # set :reverse_proxy_socket, -> { "#{shared_path}/sockets/unicorn.sock"}
116
+
117
+ #
118
+ #############
@@ -0,0 +1,95 @@
1
+ server {
2
+ listen <%= @listen_port || 80 %>;
3
+ server_name <%= @application_url.join(' ') %>;
4
+
5
+ <% if authentification? %>
6
+ # Authentification
7
+ auth_basic "Valid user required to access this server";
8
+ auth_basic_user_file <%= @authentification_file %>;
9
+ <% end %>
10
+
11
+ <% if @logs_path %>
12
+ access_log <%= @logs_path %>/access.log;
13
+ error_log <%= @logs_path %>/error.log;
14
+ <% end %>
15
+
16
+ <% unless reverse_proxy? %>
17
+ root <%= @public_path %>;
18
+ <% end %>
19
+
20
+ <% if @indexes.present? %>
21
+ index <%= @indexes.join(' ') %>;
22
+ <% end %>
23
+
24
+ location / {
25
+ <% if mod_rewrite? %>
26
+ # this serves static files that exist without running other rewrite tests
27
+ if (-f $request_filename) {
28
+ expires 30d;
29
+ break;
30
+ }
31
+
32
+ # this sends all non-existing file or directory requests to index.php
33
+ if (!-e $request_filename) {
34
+ rewrite ^(.+)$ /index.php?q=$1 last;
35
+ }
36
+ <% end %>
37
+
38
+ <% if reverse_proxy? %>
39
+ proxy_pass http://<%= @application %>_reverse_proxy;
40
+ proxy_set_header Host $host;
41
+ <% end %>
42
+ }
43
+
44
+ location ~ /\.ht {
45
+ deny all;
46
+ }
47
+
48
+ <% if php_fpm? %>
49
+ location ~ .php$ {
50
+ fastcgi_pass <%= @php_fpm_host %>:<%= @php_fpm_port %>;
51
+ fastcgi_index index.php;
52
+ fastcgi_param SCRIPT_FILENAME <%= @public_path %>$fastcgi_script_name;
53
+
54
+ fastcgi_param QUERY_STRING $query_string;
55
+ fastcgi_param REQUEST_METHOD $request_method;
56
+ fastcgi_param CONTENT_TYPE $content_type;
57
+ fastcgi_param CONTENT_LENGTH $content_length;
58
+
59
+ fastcgi_param SCRIPT_NAME $fastcgi_script_name;
60
+ fastcgi_param REQUEST_URI $request_uri;
61
+ fastcgi_param DOCUMENT_URI $document_uri;
62
+ fastcgi_param DOCUMENT_ROOT $document_root;
63
+ fastcgi_param SERVER_PROTOCOL $server_protocol;
64
+
65
+ fastcgi_param GATEWAY_INTERFACE CGI/1.1;
66
+ fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
67
+
68
+ fastcgi_param REMOTE_ADDR $remote_addr;
69
+ fastcgi_param REMOTE_PORT $remote_port;
70
+ fastcgi_param SERVER_ADDR $server_addr;
71
+ fastcgi_param SERVER_PORT $server_port;
72
+ fastcgi_param SERVER_NAME $server_name;
73
+
74
+ <% if php_build_with_force_cgi_redirect? %>
75
+ fastcgi_param REDIRECT_STATUS 200;
76
+ <% end %>
77
+ }
78
+ <% end %>
79
+
80
+ <% if passenger? %>
81
+ passenger_enabled on;
82
+ <% end %>
83
+ }
84
+
85
+ <% if reverse_proxy? %>
86
+ upstream <%= @application %>_reverse_proxy {
87
+ <% if @reverse_proxy_server_address.present? %>
88
+ server <%= @reverse_proxy_server_address %>:<%= @reverse_proxy_server_port %> fail_timeout=0;
89
+ <% end %>
90
+
91
+ <% if @reverse_proxy_socket.blank? %>
92
+ server unix:<%= @reverse_proxy_socket %>;
93
+ <% end %>
94
+ }
95
+ <% end %>
@@ -0,0 +1,12 @@
1
+ module Capistrano
2
+ module Extensions
3
+ module Version #:nodoc:
4
+ MAJOR = 1
5
+ MINOR = 0
6
+ TINY = 0
7
+
8
+ ARRAY = [MAJOR, MINOR, TINY]
9
+ STRING = ARRAY.join(".")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ # Add it to PATH
4
+ ROOT_PATH = File.expand_path(File.dirname(__FILE__))
5
+ $: << ROOT_PATH if File.directory?(ROOT_PATH) and not $:.include?(ROOT_PATH)
6
+
7
+ # Require our core extensions
8
+ require 'capistrano-exts/core_ext'
9
+
10
+ # Require requested receipts
11
+ require 'capistrano-exts/receipts' if defined?(Capistrano::Configuration)
12
+
13
+ # Require all servers
14
+ Dir["#{ROOT_PATH}/capistrano-exts/servers/*.rb"].each { |f| require f }