Skip to content

Commit c2ccd41

Browse files
committed
Use SSL and the Puma web server in production
1 parent d7dad03 commit c2ccd41

File tree

4 files changed

+15
-41
lines changed

4 files changed

+15
-41
lines changed

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: bundle exec puma -C config/puma.rb

config/database.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ test:
2121
database: db/test.sqlite3
2222

2323
production:
24-
<<: *default
25-
database: db/production.sqlite3
24+
adapter: postgresql
25+
encoding: unicode
26+
# For details on connection pooling, see Rails configuration guide
27+
# https://guides.rubyonrails.org/configuring.html#database-pooling
28+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
29+
database: sample_app_production
30+
username: sample_app
31+
password: <%= ENV['SAMPLE_APP_DATABASE_PASSWORD'] %>

config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
# config.action_cable.allowed_request_origins = [ "http://example.com", /http:\/\/example.*/ ]
4747

4848
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
49-
# config.force_ssl = true
49+
config.force_ssl = true
5050

5151
# Include generic and useful information about system operation, but avoid logging too much
5252
# information to avoid inadvertent exposure of personally identifiable information (PII).

config/puma.rb

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,10 @@
1-
# Puma can serve each request in a thread from an internal thread pool.
2-
# The `threads` method setting takes two numbers: a minimum and maximum.
3-
# Any libraries that use thread pools should be configured to match
4-
# the maximum value specified for Puma. Default is set to 5 threads for minimum
5-
# and maximum; this matches the default thread size of Active Record.
6-
#
1+
# Puma configuration file.
72
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
83
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
94
threads min_threads_count, max_threads_count
10-
11-
# Specifies the `worker_timeout` threshold that Puma will use to wait before
12-
# terminating a worker in development environments.
13-
#
14-
worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development"
15-
16-
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
17-
#
18-
port ENV.fetch("PORT") { 3000 }
19-
20-
# Specifies the `environment` that Puma will run in.
21-
#
22-
environment ENV.fetch("RAILS_ENV") { "development" }
23-
24-
# Specifies the `pidfile` that Puma will use.
5+
port ENV.fetch("PORT") { 3000 }
6+
environment ENV.fetch("RAILS_ENV") { ENV['RACK_ENV'] || "development" }
257
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
26-
27-
# Specifies the number of `workers` to boot in clustered mode.
28-
# Workers are forked web server processes. If using threads and workers together
29-
# the concurrency of the application would be max `threads` * `workers`.
30-
# Workers do not work on JRuby or Windows (both of which do not support
31-
# processes).
32-
#
33-
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
34-
35-
# Use the `preload_app!` method when specifying a `workers` number.
36-
# This directive tells Puma to first boot the application and load code
37-
# before forking the application. This takes advantage of Copy On Write
38-
# process behavior so workers use less memory.
39-
#
40-
# preload_app!
41-
42-
# Allow puma to be restarted by `bin/rails restart` command.
8+
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
9+
preload_app!
4310
plugin :tmp_restart

0 commit comments

Comments
 (0)