capistrano3-puma 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d71dc0edb29b8856ac842c1fad416d01c7f6956
4
- data.tar.gz: d31c166a6ab2e6bab255b6753a28e3b8b2b25fd5
3
+ metadata.gz: c6c36d82fbc2b6fbe3258823ecae39a395ae0e86
4
+ data.tar.gz: c016c10b8daa5ea7819246ea15f192b7b06562b0
5
5
  SHA512:
6
- metadata.gz: 3da657d08ba95d780293a1bf19997a423dd895f251eec9d58f673d8bfb9af36a696b722f4648637cecc2303f5266d96cf4bc501c66783739a16b24917a751c7e
7
- data.tar.gz: d24f24ffcc1b129c440ede8df04acd30223ff30b534358ac6b96f3e5f0db024b4be86576031ba8163273ab410aa8bf3b1beb2ce48cb8e69cda4fbbcbe0bf58b2
6
+ metadata.gz: cd75d8fc63b459a9cf42edee9ce5b4a893551d6c287519b0495c8dadc228ea3f29c1c11cfdb71f692db376814eae746fdd8e5b1c91c265eaa1fe72c400f9500d
7
+ data.tar.gz: aca7221327efcafdd53ee5dc888f9d87a6559469733c1f256c20fa9471cf5f94000bd6613f5a9d5d3540082e1106e0868d8ad42df61e3777e8ba2e7b8b18fe5d
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Capistrano::Puma
2
2
 
3
+ In the current version the gem will expect a puma.rb in the shared directory, if it does not find puma.rb in the expected place it will automatically generate one with sane defaults. Keep in mind this means a puma.rb in the config directory or subdirectories will be ignored. During preparation for deployment you must start the process initially with bundle exec cap $stage puma:start , after starting the process bundle exec cap $stage deploy will work without hanging. The need to start the process initially will be addressed in a future release.
4
+
3
5
  ## Installation
4
6
 
5
7
  Add this line to your application's Gemfile:
@@ -23,7 +25,8 @@ And then execute:
23
25
  ```
24
26
 
25
27
 
26
- Configurable options, shown here with defaults:
28
+ Configurable options, shown here with defaults: Please note the configuration options below are not required unless you are trying to override a default setting, for instance if you are deploying on a host on which you do not have sudo or root privileges and you need to restrict the path. These settings go in the deploy.rb file.
29
+
27
30
  ```ruby
28
31
  set :puma_state, "#{shared_path}/tmp/pids/puma.state"
29
32
  set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
@@ -47,6 +50,8 @@ Ensure that the following directories are shared (via ``linked_dirs``):
47
50
 
48
51
  ## Changelog
49
52
 
53
+ - 0.1.2: Gemfile are refreshed between deploys now
54
+ - 0.1.1: Initial support for Monit and configuration override added.
50
55
  - 0.1.0: Phased restart will be used if puma is in cluster mode
51
56
  - 0.0.9: puma.rb location changed to shared_path root. puma:check moved to after deploy:check
52
57
  - 0.0.8: puma.rb is automatically generated if not present. Fixed RVM issue.
@@ -54,9 +59,10 @@ Ensure that the following directories are shared (via ``linked_dirs``):
54
59
 
55
60
  ## Contributors
56
61
 
57
- [molfar](https://github.com/molfar)
58
- [ayaya](https://github.com/ayamomiji)
59
- [Shane O'Grady](https://github.com/shaneog)
62
+ - [Ruohan Chen] (https://github.com/crhan)
63
+ - [molfar](https://github.com/molfar)
64
+ - [ayaya](https://github.com/ayamomiji)
65
+ - [Shane O'Grady](https://github.com/shaneog)
60
66
 
61
67
 
62
68
  ## Contributing
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Puma
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.2'
4
4
  end
5
5
  end
@@ -11,8 +11,9 @@ namespace :puma do
11
11
 
12
12
  desc 'Install Puma jungle'
13
13
  task :install do
14
- on roles(fetch(:puma_role)) do
15
- template_puma 'run-puma.erb', "#{fetch(:tmp_dir)}/run-puma"
14
+ on roles(fetch(:puma_role)) do |role|
15
+ @role = role
16
+ template_puma 'run-puma', "#{fetch(:tmp_dir)}/run-puma", role
16
17
  execute "chmod +x #{fetch(:tmp_dir)}/run-puma"
17
18
  sudo "mv #{fetch(:tmp_dir)}/run-puma #{fetch(:puma_run_path)}"
18
19
  if test '[ -f /etc/lsb-release ]'
@@ -31,7 +32,7 @@ namespace :puma do
31
32
 
32
33
 
33
34
  def debian_install
34
- template_puma 'puma-deb.erb', "#{fetch(:tmp_dir)}/puma"
35
+ template_puma 'puma-deb', "#{fetch(:tmp_dir)}/puma", @role
35
36
  execute "chmod +x #{fetch(:tmp_dir)}/puma"
36
37
  sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
37
38
  sudo 'update-rc.d -f puma defaults'
@@ -39,7 +40,7 @@ namespace :puma do
39
40
  end
40
41
 
41
42
  def rhel_install
42
- template_puma 'puma-rpm.erb', "#{fetch(:tmp_dir)}/puma"
43
+ template_puma 'puma-rpm', "#{fetch(:tmp_dir)}/puma" , @role
43
44
  execute "chmod +x #{fetch(:tmp_dir)}/puma"
44
45
  sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
45
46
  sudo 'chkconfig --add puma'
@@ -1,6 +1,7 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
- # set :puma_monit, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
3
+ set :puma_monit_conf_dir, -> { "/etc/monit/conf.d/#{puma_monit_service_name}.conf" }
4
+ set :puma_monit_bin, -> { "/usr/bin/monit" }
4
5
  end
5
6
  end
6
7
 
@@ -9,24 +10,51 @@ namespace :puma do
9
10
  namespace :monit do
10
11
  desc 'Config Puma monit-service'
11
12
  task :config do
13
+ on roles(fetch(:puma_role)) do |role|
14
+ @role = role
15
+ template_puma 'puma_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
16
+ sudo "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:puma_monit_conf_dir)}"
17
+ end
18
+ end
19
+
20
+ desc 'Monitor Puma monit-service'
21
+ task :monitor do
12
22
  on roles(fetch(:puma_role)) do
13
- template_puma 'monit.conf.erb', "#{fetch(:tmp_dir)}/monit.test"
23
+ sudo "#{fetch(:puma_monit_bin)} monitor #{puma_monit_service_name}"
14
24
  end
15
25
  end
16
26
 
17
- desc 'Enable Puma monit-service'
18
- task :enable do
27
+ desc 'Unmonitor Puma monit-service'
28
+ task :unmonitor do
19
29
  on roles(fetch(:puma_role)) do
30
+ sudo "#{fetch(:puma_monit_bin)} unmonitor #{puma_monit_service_name}"
31
+ end
32
+ end
20
33
 
34
+ desc 'Disable Puma monit-service'
35
+ task :start do
36
+ on roles(fetch(:puma_role)) do
37
+ sudo "#{fetch(:puma_monit_bin)} start #{puma_monit_service_name}"
21
38
  end
22
39
  end
23
40
 
24
41
  desc 'Disable Puma monit-service'
25
- task :disable do
42
+ task :stop do
26
43
  on roles(fetch(:puma_role)) do
44
+ sudo "#{fetch(:puma_monit_bin)} stop #{puma_monit_service_name}"
45
+ end
46
+ end
27
47
 
48
+ desc 'Disable Puma monit-service'
49
+ task :restart do
50
+ on roles(fetch(:puma_role)) do
51
+ sudo "#{fetch(:puma_monit_bin)} restart #{puma_monit_service_name}"
28
52
  end
29
53
  end
30
54
 
55
+ def puma_monit_service_name
56
+ fetch(:puma_monit_service_name, "puma_monit_#{fetch(:application)}")
57
+ end
58
+
31
59
  end
32
60
  end
@@ -27,8 +27,8 @@ namespace :puma do
27
27
 
28
28
  desc 'Setup Puma config file'
29
29
  task :config do
30
- on roles(fetch(:puma_role)) do
31
- template_puma 'puma.rb.erb', fetch(:puma_conf)
30
+ on roles(fetch(:puma_role)) do |role|
31
+ template_puma 'puma', fetch(:puma_conf), role
32
32
  end
33
33
  end
34
34
 
@@ -41,7 +41,7 @@ namespace :puma do
41
41
  end
42
42
  end
43
43
 
44
- %w[halt stop phased-restart status].each do |command|
44
+ %w[halt stop status].each do |command|
45
45
  desc "#{command} puma"
46
46
  task command do
47
47
  on roles (fetch(:puma_role)) do
@@ -52,16 +52,19 @@ namespace :puma do
52
52
  end
53
53
  end
54
54
 
55
- desc 'Restart puma'
56
- task :restart do
57
- on roles (fetch(:puma_role)) do
58
- within current_path do
59
- if test "[ -f #{fetch(:puma_state)} ]"
60
- execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} restart"
61
- else
62
- # Puma is not running or state file is not present : Run it
63
- # TODO check for pid
64
- execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)}"
55
+
56
+ %w[phased-restart restart].each do |command|
57
+ desc "#{command} puma"
58
+ task command do
59
+ on roles (fetch(:puma_role)) do
60
+ within current_path do
61
+ if test "[ -f #{fetch(:puma_pid)} ]" and test "kill -0 $( cat #{fetch(:puma_pid)} )"
62
+ # NOTE pid exist but state file is nonsense, so ignore that case
63
+ execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
64
+ else
65
+ # Puma is not running or state file is not present : Run it
66
+ execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)}"
67
+ end
65
68
  end
66
69
  end
67
70
  end
@@ -69,12 +72,12 @@ namespace :puma do
69
72
 
70
73
 
71
74
  task :check do
72
- on roles (fetch(:puma_role)) do
75
+ on roles (fetch(:puma_role)) do |role|
73
76
  #Create puma.rb for new deployments
74
77
  unless test "[ -f #{fetch(:puma_conf)} ]"
75
78
  warn 'puma.rb NOT FOUND!'
76
79
  #TODO DRY
77
- template_puma 'puma.rb.erb', fetch(:puma_conf)
80
+ template_puma 'puma', fetch(:puma_conf), role
78
81
  info 'puma.rb generated'
79
82
  end
80
83
  end
@@ -89,17 +92,27 @@ namespace :puma do
89
92
  end
90
93
  end
91
94
 
92
- def processors_count
93
- #TODO , will be used to warn if # of workers is > of available cores
94
- capture 'grep -c processor /proc/cpuinfo'
95
- end
96
-
97
95
  def puma_workers
98
96
  fetch(:puma_workers) || 0
99
97
  end
100
98
 
101
- def template_puma(from, to)
102
- erb = File.read(File.expand_path("../../templates/#{from}", __FILE__))
103
- upload! StringIO.new(ERB.new(erb).result(binding)), to
99
+ def template_puma(from, to, role)
100
+ [
101
+ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
102
+ "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
103
+ "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
104
+ "lib/capistrano/templates/#{from}.rb.erb",
105
+ "lib/capistrano/templates/#{from}.rb",
106
+ "lib/capistrano/templates/#{from}.erb",
107
+ File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
108
+ File.expand_path("../../templates/#{from}.erb", __FILE__)
109
+ ].each do |path|
110
+ if File.file?(path)
111
+ erb = File.read(path)
112
+ upload! StringIO.new(ERB.new(erb).result(binding)), to
113
+ break
114
+ end
115
+ end
104
116
  end
117
+
105
118
  end
@@ -11,3 +11,9 @@ bind "<%=fetch(:puma_bind)%>"
11
11
 
12
12
  workers <%= puma_workers %>
13
13
  preload_app!
14
+
15
+ on_restart do
16
+ puts 'On restart...Refresh ENV["BUNDLE_GEMFILE"]'
17
+ ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
18
+ end
19
+
@@ -0,0 +1,10 @@
1
+ # Monit configuration for Puma
2
+ # Service name: <%= puma_monit_service_name %>
3
+ #
4
+ check process <%= puma_monit_service_name %>
5
+ with pidfile "<%= fetch(:puma_pid) %>"
6
+ start program = "/bin/su <%= @role.user %> -c 'source $HOME/.bashrc && cd <%= current_path %> && bundle exec puma -C <%= fetch(:puma_conf) %>'"
7
+ stop program = "/bin/su <%= @role.user %> -c 'source $HOME/.bashrc && cd <%= current_path %> && bundle exec pumactl -S <%= fetch(:puma_state) %> stop'"
8
+
9
+
10
+
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2013-12-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.0.0
27
27
  description: Puma integration for Capistrano 3
@@ -31,7 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - .gitignore
34
+ - ".gitignore"
35
35
  - Gemfile
36
36
  - LICENSE.txt
37
37
  - README.md
@@ -42,17 +42,14 @@ files:
42
42
  - lib/capistrano/puma.rb
43
43
  - lib/capistrano/puma/jungle.rb
44
44
  - lib/capistrano/puma/monit.rb
45
- - lib/capistrano/puma/nginx.rb
46
45
  - lib/capistrano/puma/version.rb
47
46
  - lib/capistrano/tasks/jungle.cap
48
47
  - lib/capistrano/tasks/monit.cap
49
- - lib/capistrano/tasks/nginx.cap
50
48
  - lib/capistrano/tasks/puma.cap
51
- - lib/capistrano/templates/monit.conf.erb
52
- - lib/capistrano/templates/nginx.conf.erb
53
49
  - lib/capistrano/templates/puma-deb.erb
54
50
  - lib/capistrano/templates/puma-rpm.erb
55
51
  - lib/capistrano/templates/puma.rb.erb
52
+ - lib/capistrano/templates/puma_monit.conf.erb
56
53
  - lib/capistrano/templates/run-puma.erb
57
54
  homepage: https://github.com/seuros/capistrano-puma
58
55
  licenses:
@@ -64,17 +61,17 @@ require_paths:
64
61
  - lib
65
62
  required_ruby_version: !ruby/object:Gem::Requirement
66
63
  requirements:
67
- - - '>='
64
+ - - ">="
68
65
  - !ruby/object:Gem::Version
69
66
  version: '0'
70
67
  required_rubygems_version: !ruby/object:Gem::Requirement
71
68
  requirements:
72
- - - '>='
69
+ - - ">="
73
70
  - !ruby/object:Gem::Version
74
71
  version: '0'
75
72
  requirements: []
76
73
  rubyforge_project:
77
- rubygems_version: 2.0.14
74
+ rubygems_version: 2.1.11
78
75
  signing_key:
79
76
  specification_version: 4
80
77
  summary: Puma integration for Capistrano
@@ -1,2 +0,0 @@
1
- #load nginx tasks
2
- load File.expand_path('../../tasks/nginx.cap', __FILE__)
@@ -1,17 +0,0 @@
1
- namespace :load do
2
- task :defaults do
3
- set :nginx_access_log, -> { File.join(shared_path, 'log', 'nginx_error.log') }
4
- set :nginx_error_log, -> { File.join(shared_path, 'log', 'nginx_access.log') }
5
- end
6
- end
7
-
8
- namespace :puma do
9
- namespace :nginx do
10
- desc 'Config Puma nginx-server'
11
- task :config do
12
- on roles(fetch(:puma_role)) do
13
- template_puma 'nginx.conf.erb', "#{fetch(:tmp_dir)}/nginx.test"
14
- end
15
- end
16
- end
17
- end
@@ -1,14 +0,0 @@
1
- # Monit configuration for Puma
2
- # Service name: <%= fetch(:puma_monit_service_name) %>
3
- #
4
- check process <%= fetch(:puma_monit_service_name) %>
5
- with pidfile <%= fetch(:puma_pid) %>
6
- start program = "/bin/su - <%= fetch(:user) %> -c '/usr/bin/env PATH=/home/user/.rbenv/shims:/home/user/.rbenv/bin:$PATH /home/user/puma.sh start'"
7
- stop program = "/bin/su - <%= fetch(:user) %> -c '/usr/bin/env PATH=/home/user/.rbenv/shims:/home/user/.rbenv/bin:$PATH /home/user/puma.sh stop'"
8
- if mem is greater than <%= fetch(:puma_monit_memory_alert_threshold) %> then alert
9
- if mem is greater than <%= fetch(:puma_monit_memory_restart_threshold) %> then restart
10
- if cpu is greater than <%= fetch(:puma_monit_cpu_alert_threshold) %> then alert
11
- if cpu is greater than <%= fetch(:puma_monit_cpu_restart_threshold) %> then restart
12
-
13
-
14
-
@@ -1,216 +0,0 @@
1
- # Nginx configuration
2
- # <%= "#{fetch(:application)} running as #{fetch(:user)} in environment production" %>
3
- #
4
- #
5
-
6
- upstream <%= fetch(:application) %> {
7
- server <%= fetch(:puma_bind) %> fail_timeout=0;
8
- }
9
-
10
- <% if fetch(:nginx_uses_http) %>
11
- #
12
- # HTTP server configuration
13
- #
14
- server {
15
- listen <%= fetch(:nginx_port) %>;
16
- client_max_body_size <%= fetch(:nginx_client_max_body_size) %>;
17
- server_name <%= fetch(:server_names, '_') %>;
18
-
19
- # ~2 seconds is often enough for most folks to parse HTML/CSS and
20
- # retrieve needed images/icons/frames, connections are cheap in
21
- # nginx so increasing this is generally safe...
22
- # 8 seconds might be needed for some mobile devs
23
- keepalive_timeout 8;
24
-
25
- # path for static files
26
- root <%= fetch(:deploy_to) %>/current/public;
27
- access_log <%= fetch(:nginx_access_log) %>;
28
- error_log <%= fetch(:nginx_error_log) %> info;
29
-
30
- # this rewrites all the requests to the maintenance.html
31
- # page if it exists in the doc root. This is for capistrano's
32
- # disable web task
33
- if (-f $document_root/system/maintenance.html) {
34
- rewrite ^(.*)$ /system/maintenance.html last;
35
- break;
36
- }
37
-
38
- location / {
39
- <% if fetch(:nginx_use_simple_auth) %>
40
- auth_basic "<%= fetch(:nginx_simple_auth_message) %>";
41
- auth_basic_user_file <%= fetch(:nginx_remote_htpasswd) %>;
42
- <% end %>
43
-
44
- # needed to forward user's IP address to rails
45
- proxy_set_header X-Real-IP $remote_addr;
46
-
47
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
48
- proxy_set_header Host $http_host;
49
-
50
- # if the request is for a static resource, nginx should serve it directly
51
- # and add a far future expires header to it, making the browser
52
- # cache the resource and navigate faster over the website.
53
- location ~ ^/(assets)/.+-([0-9a-zA-Z])+\. {
54
- gzip_static on;
55
- expires max;
56
- add_header Cache-Control public;
57
- }
58
-
59
- # Serve images outside the asset path
60
- # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
61
- # BUT there's a chance it could break the ajax calls.
62
- location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
63
- expires max;
64
- }
65
-
66
- # Serve javascript outside the asset path
67
- location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
68
- expires max;
69
- }
70
-
71
- # If the file exists as a static file serve it directly without
72
- # running all the other rewrite tests on it
73
- if (-f $request_filename) {
74
- break;
75
- }
76
-
77
- # check for index.html for directory index
78
- # if its there on the filesystem then rewite
79
- # the url to add /index.html to the end of it
80
- # and then break to send it to the next config rules.
81
- if (-f $request_filename/index.html) {
82
- rewrite (.*) $1/index.html break;
83
- }
84
-
85
- # this is the meat of the rails page caching config
86
- # it adds .html to the end of the url and then checks
87
- # the filesystem for that file. If it exists, then we
88
- # rewite the url to have explicit .html on the end
89
- # and then send it on its way to the next config rule.
90
- # if there is no file on the fs then it sets all the
91
- # necessary headers and proxies to our upstream mongrels
92
- if (-f $request_filename.html) {
93
- rewrite (.*) $1.html break;
94
- }
95
-
96
- if (!-f $request_filename) {
97
- proxy_pass http://<%= upstream_name %>;
98
- break;
99
- }
100
- }
101
-
102
- # Rails error pages
103
- error_page 500 502 503 504 /500.html;
104
- location = /500.html {
105
- root <%= fetch(:deploy_to) %>/current/public;
106
- }
107
- }
108
- <% end %>
109
-
110
- <% if fetch(:nginx_uses_ssl) %>
111
- #
112
- # HTTPs server configuration
113
- #
114
- upstream <%= upstream_name_ssl %> {
115
- server unix:<%= File.join("#{fetch(:shared_path)}","sockets", "puma.sock") %> fail_timeout=0;
116
- }
117
-
118
- # This server is setup for ssl. Uncomment if
119
- # you are using ssl as well as port 80.
120
- server {
121
- listen <%= fetch(:nginx_ssl_port) %>;
122
- client_max_body_size 500M;
123
- server_name <%= fetch(:server_names) %>;
124
- ssl on;
125
- ssl_certificate <%= fetch(:nginx_ssl_public_crt) %>;
126
- ssl_certificate_key <%= fetch(:nginx_ssl_private_key) %>;
127
- ssl_session_timeout 5m;
128
- client_max_body_size <%= fetch(:nginx_ssl_client_max_body_size) %>;
129
-
130
- root <%= fetch(:deploy_to) %>/current/public;
131
- access_log <%= fetch(:nginx_log_path) %>;
132
- error_log <%= fetch(:nginx_log_path) %> info;
133
-
134
- # this rewrites all the requests to the maintenance.html
135
- # page if it exists in the doc root. This is for capistrano's
136
- # disable web task
137
- if (-f $document_root/system/maintenance.html) {
138
- rewrite ^(.*)$ /system/maintenance.html last;
139
- break;
140
- }
141
-
142
- location / {
143
- <% if fetch(:nginx_ssl_use_simple_auth) %>
144
- auth_basic "<%= fetch(:nginx_simple_auth_message) %>";
145
- auth_basic_user_file <%= fetch(:nginx_remote_htpasswd) %>;
146
- <% end %>
147
-
148
- # needed to forward user's IP address to rails
149
- proxy_set_header X-Real-IP $remote_addr;
150
-
151
- # needed for HTTPS
152
- proxy_set_header X_FORWARDED_PROTO https;
153
-
154
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
155
- proxy_set_header Host $http_host;
156
- proxy_redirect off;
157
- proxy_max_temp_file_size 0;
158
-
159
- # if the request is for a static resource, nginx should serve it directly
160
- # and add a far future expires header to it, making the browser
161
- # cache the resource and navigate faster over the website.
162
- location ~ ^/(assets)/.+-([0-9a-zA-Z])+\. {
163
- gzip_static on;
164
- expires max;
165
- add_header Cache-Control public;
166
- }
167
-
168
- # Serve images outside the asset path
169
- # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
170
- # BUT there's a chance it could break the ajax calls.
171
- location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
172
- expires max;
173
- }
174
-
175
- # Serve javascript outside the asset path
176
- location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
177
- expires max;
178
- }
179
-
180
- # If the file exists as a static file serve it directly without
181
- # running all the other rewite tests on it
182
- if (-f $request_filename) {
183
- break;
184
- }
185
-
186
- # check for index.html for directory index
187
- # if its there on the filesystem then rewite
188
- # the url to add /index.html to the end of it
189
- # and then break to send it to the next config rules.
190
- if (-f $request_filename/index.html) {
191
- rewrite (.*) $1/index.html break;
192
- }
193
-
194
- # this is the meat of the rails page caching config
195
- # it adds .html to the end of the url and then checks
196
- # the filesystem for that file. If it exists, then we
197
- # rewite the url to have explicit .html on the end
198
- # and then send it on its way to the next config rule.
199
- # if there is no file on the fs then it sets all the
200
- # necessary headers and proxies to our upstream mongrels
201
- if (-f $request_filename.html) {
202
- rewrite (.*) $1.html break;
203
- }
204
-
205
- if (!-f $request_filename) {
206
- proxy_pass http://<%= upstream_name_ssl %>;
207
- break;
208
- }
209
- }
210
-
211
- error_page 500 502 503 504 /500.html;
212
- location = /500.html {
213
- root <%= fetch(:deploy_to) %>/current/public;
214
- }
215
- }
216
- <% end %>