PageSourceSearch

https://puma.io/puma7/

html puma.io collected 2026-09-24 08:42:25 UTC 44,495 bytes, 349 lines download raw bytes

1<!DOCTYPE html>
2<html>
3<head>
4
5<meta charset='UTF-8'>
6<meta name='viewport' content='width=device-width, initial-scale=1.0, user-scalable=no'>
7<meta name='apple-touch-fullscreen' content='yes'>
8<meta name='mobile-web-app-capable' content='yes'>
9<meta name='apple-mobile-web-app-status-bar-style' content='rgba(228,228,228,1.0)'>
10
11<title>File: README &mdash; Puma-7.2.1</title>
12
13<link rel='stylesheet'  type='text/css' href='css/y_fonts.css' />
14<link rel='stylesheet'  type='text/css' href='css/highlight.github.css' />
15<link rel='stylesheet'  type='text/css' href='css/y_style.css' />
16<link rel='stylesheet'  type='text/css' href='css/y_list.css' />
17<link rel='stylesheet'  type='text/css' href='css/y_color.css' />
18
19<script type='text/javascript'>
20  var pathId = "README",
21    relpath = '';
22
23  var t2Info = {
24    CSEP: '.',
25    ISEP: '#',
26    NSEP: '::'
27  };
28</script>
28
29
30<script type='text/javascript' charset='utf-8' src='js/highlight.pack.js'></script>
vendor: 1 bytes, line 30
30
31<script type='text/javascript' charset='utf-8' src='js/y_app.js'></script>
31
32
33</head>
34<body>
35<svg id='y_wait' class viewBox='0 0 90 90'></svg>
36<div id='settings' class='hidden'></div>
37<div id='y_list' class='d h'>
38  <header id='list_header'></header>
39  <nav id= 'list_nav' class='y_nav l_nav'>
40    <ul id='list_items'></ul>
41  </nav>
42</div>
43<div id='y_toc' class='f h'>
44  <header id='toc_header'></header>
45  <nav id= 'toc_nav' class='y_nav t_nav'>
46  <ol id='toc_items'></ol>
47  </nav>
48</div>
49<div id='y_main' tabindex='-1'>
50  <header id='y_header'>
51    <div id='y_menu'>
52      <a id='home_no_xhr' href='/'>Home</a> &raquo; 
53      <a href='.'>Puma-7.2.1</a> &raquo; 
54      <a href='_index.html'>Index</a> &raquo; 
55      <span class='title'><a id='t2_doc_top' href='#'>File: README&nbsp;&#x25B2;</a></span>
56          </div>
57
58    <a id='list_href' href="class_list.html"></a>
59    <div id='y_measure_em' class='y_measure'></div>
60    <div id='y_measure_vh' class='y_measure'></div>
61    <span id='y_measure_50pre' class='y_measure'><code>123456789_123456789_123456789_123456789_123456789_</code></span>
62  </header>
63<div id='content' class='file'>
64<p align="center">
65  <img style="min-width:50%;" src="images/standard-logo.svg">
66</p>
67<h1 id="Puma__A_Ruby_Web_Server_Built_For_Parallelism">Puma: A Ruby Web Server Built For Parallelism</h1>
68<p><a href="https://github.com/puma/puma/actions/runs/26482430234"><img src="https://github.com/puma/puma/actions/workflows/tests.yml/badge.svg?tag=v7.2.1" alt="Actions"></a>
69<a href="https://stackoverflow.com/questions/tagged/puma"><img src="https://img.shields.io/badge/stackoverflow-Puma-blue.svg" alt="StackOverflow" /></a></p>
70<p><a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is a <strong>simple, fast, multi-threaded, and highly parallel HTTP 1.1 server for Ruby/Rack applications</strong>.</p>
71<h2 id="Built_For_Speed__amp__Parallelism">Built For Speed &amp; Parallelism</h2>
72<p><a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is a server for <a href="https://github.com/rack/rack">Rack</a>-powered HTTP applications written in Ruby.  It is:</p>
73<ul>
74<li><strong>Multi-threaded</strong>. Each request is served in a separate thread. This helps you serve more requests per second with less memory use.</li>
75<li><strong>Multi-process</strong>. &quot;Pre-forks&quot; in cluster mode, using less memory per-process thanks to copy-on-write memory.</li>
76<li><strong>Standalone</strong>. With SSL support, zero-downtime rolling restarts and a built-in request bufferer, you can deploy <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> without any reverse proxy.</li>
77<li><strong>Battle-tested</strong>. Our HTTP parser is inherited from Mongrel and has over 15 years of production use. <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> is currently the most popular Ruby webserver, and is the default server for Ruby on Rails.</li>
78</ul>
79<p>Originally designed as a server for <a href="https://github.com/rubinius/rubinius">Rubinius</a>, <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> also works well with Ruby (MRI) and JRuby.</p>
80<p>On MRI, there is a Global VM Lock (GVL) that ensures only one thread can run Ruby code at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), <a href="Puma.html" title="Puma (module)"><code>Puma</code></a> still improves MRI's throughput by allowing IO waiting to be done in parallel. Truly parallel Ruby implementations (TruffleRuby, JRuby) don't have this limitation.</p>
81<h2 id="Quick_Start">Quick Start</h2>
82<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_puma'>puma</span>
83<span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span></code></pre>
84<p>Without arguments, puma will look for a rackup (.ru) file in
85working directory called <code>config.ru</code>.</p>
86<h2 id="SSL_Connection_Support">SSL Connection Support</h2>
87<p>Puma will install/compile with support for ssl sockets, assuming OpenSSL
88development files are installed on the system.</p>
89<p>If the system does not have OpenSSL development files installed, Puma will
90install/compile, but it will not allow ssl connections.</p>
91<h2 id="Frameworks">Frameworks</h2>
92<h3 id="Rails">Rails</h3>
93<p>Puma is the default server for Rails, included in the generated Gemfile.</p>
94<p>Start your server with the <code>rails</code> command:</p>
95<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_rails'>rails</span> <span class='id identifier rubyid_server'>server</span></code></pre>
96<p>Many configuration options and Puma features are not available when using <code>rails server</code>. It is recommended that you use Puma's executable instead:</p>
97<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_puma'>puma</span></code></pre>
98<h3 id="Sinatra">Sinatra</h3>
99<p>You can run your Sinatra application with Puma from the command line like this:</p>
100<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_ruby'>ruby</span> <span class='id identifier rubyid_app'>app</span>.<span class='id identifier rubyid_rb'>rb</span> <span class='op'>-</span><span class='id identifier rubyid_s'>s</span> <span class='const'><a href="Puma.html" title="Puma (module)">Puma</a></span></code></pre>
101<p>In order to actually configure Puma using a config file, like <code>puma.rb</code>, however, you need to use the <code>puma</code> executable. To do this, you must add a rackup file to your Sinatra app:</p>
102<pre class="code ruby"><code class="ruby"><span class='comment'># config.ru
103</span><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>./app</span><span class='tstring_end'>&#39;</span></span>
104<span class='id identifier rubyid_run'>run</span> <span class='const'>Sinatra</span><span class='op'>::</span><span class='const'>Application</span></code></pre>
105<p>You can then start your application using:</p>
106<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_puma'>puma</span></code></pre>
107<h2 id="Configuration">Configuration</h2>
108<p>Puma provides numerous options. Consult <code>puma -h</code> (or <code>puma --help</code>) for a full list of CLI options, or see <a href="Puma/DSL.html" title="Puma::DSL (class)"><code>DSL</code></a> or <a href="https://github.com/puma/puma/blob/main/lib/puma/dsl.rb">dsl.rb</a>.</p>
109<p>You can also find several configuration examples as part of the
110<a href="https://github.com/puma/puma/tree/main/test/config">test</a> suite.</p>
111<p>For debugging purposes, you can set the environment variable <code>PUMA_LOG_CONFIG</code> with a value
112and the loaded configuration will be printed as part of the boot process.</p>
113<h3 id="Thread_Pool">Thread Pool</h3>
114<p>Puma uses a thread pool. You can set the minimum and maximum number of threads that are available in the pool with the <code>-t</code> (or <code>--threads</code>) flag:</p>
115<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span></code></pre>
116<p>Puma will automatically scale the number of threads, from the minimum until it caps out at the maximum, based on how much traffic is present. The current default is <code>0:16</code> and on MRI is <code>0:5</code>. Feel free to experiment, but be careful not to set the number of maximum threads to a large number, as you may exhaust resources on the system (or cause contention for the Global VM Lock, when using MRI).</p>
117<p>Be aware that additionally Puma creates threads on its own for internal purposes (e.g. handling slow clients). So, even if you specify -t 1:1, expect around 7 threads created in your application.</p>
118<h3 id="Cluster_mode">Cluster mode</h3>
119<p>Puma also offers &quot;cluster mode&quot;. Cluster mode <code>fork</code>s workers from a master process. Each child process still has its own thread pool. You can tune the number of workers with the <code>-w</code> (or <code>
119--workers</code>) flag:</p>
120<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span> <span class='op'>-</span><span class='id identifier rubyid_w'>w</span> <span class='int'>3</span></code></pre>
121<p>Or with the <code>WEB_CONCURRENCY</code> environment variable:</p>
122<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='const'>WEB_CONCURRENCY</span><span class='op'>=</span><span class='int'>3</span> <span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_t'>t</span> <span class='int'>8</span><span class='symbeg'>:</span><span class='int'>32</span></code></pre>
123<p>When using a config file, most applications can simply set <code>workers :auto</code> (requires the <code>concurrent-ruby</code> gem) to match the number of worker processes to the available processors:</p>
124<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
125</span><span class='id identifier rubyid_workers'>workers</span> <span class='symbeg'>:</span><span class='id identifier rubyid_auto'>auto</span></code></pre>
126<p>See <a href="lib/puma/dsl.rb"><code>workers :auto</code> gotchas</a>.</p>
127<p>Note that threads are still used in cluster mode, and the <code>-t</code> thread flag setting is per worker, so <code>-w 2 -t 16:16</code> will spawn 32 threads in total, with 16 in each worker process.</p>
128<p>If <code>workers</code> is set to <code>:auto</code>, or the <code>WEB_CONCURRENCY</code> environment variable is set to <code>&quot;auto&quot;</code>, and the <code>concurrent-ruby</code> gem is available in your application, Puma will set the worker process count to the result of <a href="https://msp-greg.github.io/concurrent-ruby/Concurrent.html#available_processor_count-class_method">available processors</a>.</p>
129<p>For an in-depth discussion of the tradeoffs of thread and process count settings, <a href="file.deployment.html">see our docs</a>.</p>
130<p>In cluster mode, Puma can &quot;preload&quot; your application. This loads all the application code <em>prior</em> to forking. Preloading reduces total memory usage of your application via an operating system feature called <a href="https://en.wikipedia.org/wiki/Copy-on-write">copy-on-write</a>.</p>
131<p>If the number of workers is greater than 1 (and <code>--prune-bundler</code> has not been specified), preloading will be enabled by default. Otherwise, you can use the <code>--preload</code> flag from the command line:</p>
132<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_w'>w</span> <span class='int'>3</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_preload'>preload</span></code></pre>
133<p>Or, if you're using a configuration file, you can use the <code>preload_app!</code> method:</p>
134<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
135</span><span class='id identifier rubyid_workers'>workers</span> <span class='int'>3</span>
136<span class='id identifier rubyid_preload_app!'>preload_app!</span></code></pre>
137<p>Preloading can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preloading copies the code of master into the workers.</p>
138<h4 id="Cluster_mode_hooks">Cluster mode hooks</h4>
139<p>When using clustered mode, Puma's configuration DSL provides <code>before_fork</code>, <code>before_worker_boot</code>, and <code>after_worker_shutdown</code>
140hooks to run code when the master process forks, the child workers are booted, and after each child worker exits respectively.</p>
141<p>It is recommended to use these hooks with <code>preload_app!</code>, otherwise constants loaded by your
142application (such as <code>Rails</code>) will not be available inside the hooks.</p>
143<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
144</span><span class='id identifier rubyid_before_fork'>before_fork</span> <span class='kw'>do</span>
145  <span class='comment'># Add code to run inside the Puma master process before it forks a worker child.
146</span><span class='kw'>end</span>
147
148<span class='id identifier rubyid_before_worker_boot'>before_worker_boot</span> <span class='kw'>do</span>
149  <span class='comment'># Add code to run inside the Puma worker process after forking.
150</span><span class='kw'>end</span>
151
152<span class='id identifier rubyid_after_worker_shutdown'>after_worker_shutdown</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_worker_handle'>worker_handle</span><span class='op'>|</span>
153  <span class='comment'># Add code to run inside the Puma master process after a worker exits. `worker.process_status` can be used to get the
154</span>  <span class='comment'># {Process::Status} of the exited worker.
155</span><span class='kw'>end</span></code></pre>
156<p>In addition, there is an <code>before_refork</code> and <code>after_refork</code> hooks which are used only in <a href="file.fork_worker.html"><code>fork_worker</code> mode</a>,
157when the worker 0 child process forks a grandchild worker:</p>
158<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_before_refork'>before_refork</span> <span class='kw'>do</span>
159  <span class='comment'># Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
160</span>  <span class='comment'># child process before it forks a grandchild worker.
161</span><span class='kw'>end</span></code></pre>
162<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_after_refork'>after_refork</span> <span class='kw'>do</span>
163  <span class='comment'># Used only when fork_worker mode is enabled. Add code to run inside the Puma worker 0
164</span>  <span class='comment'># child process after it forks a grandchild worker.
165</span><span class='kw'>end</span></code></pre>
166<p>Importantly, note the following considerations when Ruby forks a child process:</p>
167<ol>
168<li>File descriptors such as network sockets <strong>are</strong> copied from the parent to the forked
169child process. Dual-use of the same sockets by parent and child will result in I/O conflicts
170such as <code>SocketError</code>, <code>Errno::EPIPE</code>, and <code>EOFError</code>.</li>
171<li>
171Background Ruby threads, including threads used by various third-party gems for connection
172monitoring, etc., are <strong>not</strong> copied to the child process. Often this does not cause
173immediate problems until a third-party connection goes down, at which point there will
174be no supervisor to reconnect it.</li>
175</ol>
176<p>Therefore, we recommend the following:</p>
177<ol>
178<li>If possible, do not establish any socket connections (HTTP, database connections, etc.)
179inside Puma's master process when booting.</li>
180<li>If (1) is not possible, use <code>before_fork</code> and <code>before_refork</code> to disconnect the parent's socket
181connections when forking, so that they are not accidentally copied to the child process.</li>
182<li>Use <code>before_worker_boot</code> to restart any background threads on the forked child.</li>
183<li>Use <code>after_refork</code> to restart any background threads on the parent.</li>
184</ol>
185<h4 id="Master_process_lifecycle_hooks">Master process lifecycle hooks</h4>
186<p>Puma's configuration DSL provides master process lifecycle hooks <code>after_booted</code>, <code>before_restart</code>, and <code>after_stopped</code>
187which may be used to specify code blocks to run on each event:</p>
188<pre class="code ruby"><code class="ruby"><span class='comment'># config/puma.rb
189</span><span class='id identifier rubyid_after_booted'>after_booted</span> <span class='kw'>do</span>
190  <span class='comment'># Add code to run in the Puma master process after it boots,
191</span>  <span class='comment'># and also after a phased restart completes.
192</span><span class='kw'>end</span>
193
194<span class='id identifier rubyid_before_restart'>before_restart</span> <span class='kw'>do</span>
195  <span class='comment'># Add code to run in the Puma master process when it receives
196</span>  <span class='comment'># a restart command but before it restarts.
197</span><span class='kw'>end</span>
198
199<span class='id identifier rubyid_after_stopped'>after_stopped</span> <span class='kw'>do</span>
200  <span class='comment'># Add code to run in the Puma master process when it receives
201</span>  <span class='comment'># a stop command but before it shuts down.
202</span><span class='kw'>end</span></code></pre>
203<h3 id="Error_handling">Error handling</h3>
204<p>If Puma encounters an error outside of the context of your application, it will respond with a 400/500 and a simple
205textual error message (see <a href="Puma/Server.html#lowlevel_error-instance_method" title="Puma::Server#lowlevel_error (method)">Puma::Server#lowlevel_error</a> or <a href="https://github.com/puma/puma/blob/main/lib/puma/server.rb">server.rb</a>).
206You can specify custom behavior for this scenario. For example, you can report the error to your third-party
207error-tracking service (in this example, <a href="https://rollbar.com">rollbar</a>):</p>
208<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_lowlevel_error_handler'>lowlevel_error_handler</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_e'>e</span><span class='comma'>,</span> <span class='id identifier rubyid_env'>env</span><span class='comma'>,</span> <span class='id identifier rubyid_status'>status</span><span class='op'>|</span>
209  <span class='kw'>if</span> <span class='id identifier rubyid_status'>status</span> <span class='op'>==</span> <span class='int'>400</span>
210    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>The server could not process the request due to an error, such as an incorrectly typed URL, malformed syntax, or a URL that contains illegal characters.\n</span><span class='tstring_end'>&quot;</span></span>
211  <span class='kw'>else</span>
212    <span class='id identifier rubyid_message'>message</span> <span class='op'>=</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>An error has occurred, and engineers have been informed. Please reload the page. If you continue to have problems, contact [email protected]\n</span><span class='tstring_end'>&quot;</span></span>
213    <span class='const'>Rollbar</span>.<span class='id identifier rubyid_critical'>critical</span>(<span class='id identifier rubyid_e'>e</span>)
214  <span class='kw'>end</span>
215
216  [<span class='id identifier rubyid_status'>status</span><span class='comma'>,</span> {}<span class='comma'>,</span> [<span class='id identifier rubyid_message'>message</span>]]
217<span class='kw'>end</span></code></pre>
218<h3 id="Binding_TCP___Sockets">Binding TCP / Sockets</h3>
219<p>Bind Puma to a socket with the <code>-b</code> (or <code>--bind</code>) flag:</p>
220<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='label'>tcp:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='float'>127.0</span><span class='op'>:</span><span class='int'>
2209292</span></code></pre>
221<p>To use a UNIX Socket instead of TCP:</p>
222<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='label'>unix:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='op'>/</span><span class='id identifier rubyid_var'>var</span><span class='op'>/</span><span class='id identifier rubyid_run'>run</span><span class='op'>/</span><span class='id identifier rubyid_puma'>puma</span>.<span class='id identifier rubyid_sock'>sock</span></code></pre>
223<p>If you need to change the permissions of the UNIX socket, just add a umask parameter:</p>
224<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>unix:///var/run/puma.sock?umask=0111</span><span class='tstring_end'>&#39;</span></span></code></pre>
225<p>Need a bit of security? Use SSL sockets:</p>
226<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert</span><span class='tstring_end'>&#39;</span></span></code></pre>
227<h4 id="Self_signed_SSL_certificates__via_the___localhost___gem__for_development_use__">Self-signed SSL certificates (via the [<code>localhost</code>] gem, for development use):</h4>
228<p>Puma supports the [<code>localhost</code>] gem for self-signed certificates. This is particularly useful if you want to use Puma with SSL locally, and self-signed certificates will work for your use-case. Currently, the integration can only be used in MRI.</p>
229<p>Puma automatically configures SSL when the [<code>localhost</code>] gem is loaded in a <code>development</code> environment:</p>
230<p>Add the gem to your Gemfile:</p>
231<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_group'>group</span>(<span class='symbeg'>:</span><span class='id identifier rubyid_development'>development</span>) <span class='kw'>do</span>
232  <span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>localhost</span><span class='tstring_end'>&#39;</span></span>
233<span class='kw'>end</span></code></pre>
234<p>And require it implicitly using bundler:</p>
235<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>bundler</span><span class='tstring_end'>&quot;</span></span>
236<span class='const'>Bundler</span>.<span class='id identifier rubyid_require'>require</span>(<span class='symbeg'>:</span><span class='id identifier rubyid_default'>default</span><span class='comma'>,</span> <span class='const'>ENV</span>[<span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>RACK_ENV</span><span class='tstring_end'>&quot;</span></span>].<span class='id identifier rubyid_to_sym'>to_sym</span>)</code></pre>
237<p>Alternatively, you can require the gem in your configuration file, either <code>config/puma/development.rb</code>, <code>config/puma.rb</code>, or set via the <code>-C</code> cli option:</p>
238<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>localhost</span><span class='tstring_end'>&#39;</span></span>
239<span class='comment'># configuration methods (from Puma::DSL) as needed</span></code></pre>
240<p>Additionally, Puma must be listening to an SSL socket:</p>
241<pre class="code shell"><code class="shell">$ puma -b &#39;ssl://localhost:9292&#39; -C config/use_local_host.rb
242
243# The following options allow you to reach Puma over HTTP as well:
244$ puma -b ssl://localhost:9292 -b tcp://localhost:9393 -C config/use_local_host.rb
245</code></pre>
246<h4 id="Controlling_SSL_Cipher_Suites">Controlling SSL Cipher Suites</h4>
247<p>To use or avoid specific SSL ciphers for TLSv1.2 and below, use <code>ssl_cipher_filter</code> or <code>ssl_cipher_list</code>
247 options.</p>
248<h5 id="Ruby_">Ruby:</h5>
249<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;ssl_cipher_filter=!aNULL:AES+SHA</span><span class='tstring_end'>&#39;</span></span></code></pre>
250<h5 id="JRuby_">JRuby:</h5>
251<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?keystore=path_to_keystore&amp;keystore-pass=keystore_password&amp;ssl_cipher_list=TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA</span><span class='tstring_end'>&#39;</span></span></code></pre>
252<p>To configure the available TLSv1.3 ciphersuites, use <code>ssl_ciphersuites</code> option (not available for JRuby).</p>
253<h5 id="Ruby_">Ruby:</h5>
254<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;ssl_ciphersuites=TLS_AES_256_GCM_SHA384:TLS_AES_128_GCM_SHA256</span><span class='tstring_end'>&#39;</span></span></code></pre>
255<p>See <a href="https://www.openssl.org/docs/man1.1.1/man1/ciphers.html">https://www.openssl.org/docs/man1.1.1/man1/ciphers.html</a> for cipher filter format and full list of cipher suites.</p>
256<p>Disable TLS v1 with the <code>no_tlsv1</code> option:</p>
257<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;no_tlsv1=true</span><span class='tstring_end'>&#39;</span></span></code></pre>
258<h4 id="Controlling_OpenSSL_Verification_Flags">Controlling OpenSSL Verification Flags</h4>
259<p>To enable verification flags offered by OpenSSL, use <code>verification_flags</code> (not available for JRuby):</p>
260<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;verification_flags=PARTIAL_CHAIN</span><span class='tstring_end'>&#39;</span></span></code></pre>
261<p>You can also set multiple verification flags (by separating them with a comma):</p>
262<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;verification_flags=PARTIAL_CHAIN,CRL_CHECK</span><span class='tstring_end'>&#39;</span></span></code></pre>
263<p>List of available flags: <code>USE_CHECK_TIME</code>, <code>CRL_CHECK</code>, <code>CRL_CHECK_ALL</code>, <code>IGNORE_CRITICAL</code>, <code>X509_STRICT</code>, <code>ALLOW_PROXY_CERTS</code>, <code>POLICY_CHECK</code>, <code>EXPLICIT_POLICY</code>, <code>INHIBIT_ANY</code>, <code>INHIBIT_MAP</code>, <code>NOTIFY_POLICY</code>, <code>EXTENDED_CRL_SUPPORT</code>, <code>USE_DELTAS</code>, <code>CHECK_SS_SIGNATURE</code>, <code>TRUSTED_FIRST</code>, <code>SUITEB_128_LOS_ONLY</code>, <code>SUITEB_192_LOS</code>, <code>SUITEB_128_LOS</code>, <code>PARTIAL_CHAIN</code>, <code>NO_ALT_CHAINS</code>, <code>NO_CHECK_TIME</code>
264(see <a href="https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS">https://www.openssl.org/docs/manmaster/man3/X509_VERIFY_PARAM_set_hostflags.html#VERIFICATION-FLAGS</a>).</p>
265<h4 id="Controlling_OpenSSL_Password_Decryption">Controlling OpenSSL Password Decryption</h4>
266<p>To enable runtime decryption of an encrypted SSL key (not available for JRuby), use <code>key_password_command</code>:</p>
267<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='id identifier rubyid_b'>b</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>ssl://127.0.0.1:9292?key=path_to_key&amp;cert=path_to_cert&amp;key_password_command=/path/to/command.sh</span><span class='tstring_end'>&#39;</span></span></code></pre>
268<p><code>key_password_command</code> must:</p>
269<ol>
270<li>Be executable by Puma.</li>
271<li>Print the decryption password to stdout.</li>
272</ol>
273<p>For example:</p>
274<pre class="code shell"><code class="shell">#!/bin/sh
275
276echo &quot;this is my password&quot;
277</code></pre>
278<p><code>key_password_command</code> can be used with <code>key</code> or <code>key_pem</code>. If the key
279is not encrypted, the executable will not be called.</p>
280<h3 id="Control_Status_Server">Control/Status Server</h3>
281<p>Puma has a built-in status and control app that can be used to query and control Puma.</p>
282<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_url'>url</span> <span class='label'>tcp:</span><span class='tstring'><span class='regexp_beg'>/</span><span class='regexp_end'>/</span></span><span class='float'>127.0</span><span class='op'>:</span><span class='int'>9293</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_token'>token</span> <span class='id identifier rubyid_foo'>foo</span></code></pre>
283<p>Puma will start the control server on localhost port 9293. All requests to the control server will need to include control token (in this case, <code>token=foo</code>) as a query parameter. This allows for simple authentication. Check out <a href="Puma/App/Status.html" title="Puma::App::Status (class)"><code>App::Status</code></a> or <a href="https://github.com/puma/puma/blob/main/lib/puma/app/status.rb">status.rb</a> to see what the status app has available.</p>
284<p>You can also interact with the control server via <code>pumactl</code>. This command will restart Puma:</p>
285<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_pumactl'>pumactl</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_url'>url</span> <span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>tcp://127.0.0.1:9293</span><span class='tstring_end'>&#39;</span></span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_control'>control</span><span class='op'>-</span><span class='id identifier rubyid_token'>token</span> <span class='id identifier rubyid_foo'>foo</span> <span class='id identifier rubyid_restart'>restart</span></code></pre>
286<p>To see a list of <code>pumactl</code> options, use <code>pumactl --help</code>.</p>
287<h3 id="Configuration_File">Configuration File</h3>
288<p>You can also provide a configuration file with the <code>-C</code> (or <code>--config</code>) flag:</p>
289<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='const'>C</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>path</span><span class='regexp_end'>/to</span></span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>config</span></code></pre>
290<p>If no configuration file is specified, Puma will look for a configuration file at <code>config/puma.rb</code>. If an environment is specified (via the <code>--environment</code> flag or through the <code>APP_ENV</code>, <code>RACK_ENV</code>, or <code>RAILS_ENV</code> environment variables) Puma looks for a configuration file at <code>config/puma/&lt;environment_name&gt;.rb</code> and then falls back to <code>config/puma.rb</code>.</p>
291<p>If you want to prevent Puma from looking for a configuration file in those locations, include the <code>--no-config</code> flag:</p>
292<pre class="code ruby"><code class="ruby"><span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='op'>-</span><span class='id identifier rubyid_no'>no</span><span class='op'>-</span><span class='id identifier rubyid_config'>config</span>
293
294<span class='comment'># or
295</span>
296<span class='gvar'>$ </span><span class='id identifier rubyid_puma'>puma</span> <span class='op'>-</span><span class='const'>C</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>-</span><span class='tstring_end'>&quot;</span></span></code></pre>
297<p>The other side-effects of setting the environment are whether to show stack traces (in <code>development</code> or <code>test</code>), and setting RACK_ENV may potentially affect middleware looking for this value to change their behavior. The default puma RACK_ENV value is <code>development</code>
297. You can see all config default values in <a href="Puma/Configuration.html#puma_default_options-instance_method" title="Puma::Configuration#puma_default_options (method)">Puma::Configuration#puma_default_options</a> or <a href="https://github.com/puma/puma/blob/61c6213fbab/lib/puma/configuration.rb#L182-L204">configuration.rb</a>.</p>
298<p>Check out <a href="Puma/DSL.html" title="Puma::DSL (class)"><code>DSL</code></a> or <a href="https://github.com/puma/puma/blob/main/lib/puma/dsl.rb">dsl.rb</a> to see all available options.</p>
299<h2 id="Restart">Restart</h2>
300<p>Puma includes the ability to restart itself. When available (MRI, Rubinius, JRuby), Puma performs a &quot;hot restart&quot;. This is the same functionality available in <em>Unicorn</em> and <em>NGINX</em> which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.</p>
301<p>For more, see the <a href="file.restart.html">Restart documentation</a>.</p>
302<h2 id="Signals">Signals</h2>
303<p>Puma responds to several signals. A detailed guide to using UNIX signals with Puma can be found in the <a href="file.signals.html">Signals documentation</a>.</p>
304<h2 id="Platform_Constraints">Platform Constraints</h2>
305<p>Some platforms do not support all Puma features.</p>
306<pre class="code ruby"><code class="ruby"><span class='op'>*</span> <span class='op'>**</span><span class='const'>JRuby</span><span class='op'>**</span><span class='comma'>,</span> <span class='op'>**</span><span class='const'>Windows</span><span class='op'>**</span><span class='op'>:</span> <span class='id identifier rubyid_server'>server</span> <span class='id identifier rubyid_sockets'>sockets</span> <span class='id identifier rubyid_are'>are</span> <span class='kw'>not</span> <span class='id identifier rubyid_seamless'>seamless</span> <span class='id identifier rubyid_on'>on</span> <span class='id identifier rubyid_restart'>restart</span><span class='comma'>,</span> <span class='id identifier rubyid_they'>they</span> <span class='id identifier rubyid_must'>must</span> <span class='id identifier rubyid_be'>be</span> <span class='id identifier rubyid_closed'>closed</span> <span class='kw'>and</span> <span class='id identifier rubyid_reopened'>reopened</span>. <span class='const'>
306These</span> <span class='id identifier rubyid_platforms'>platforms</span> <span class='id identifier rubyid_have'>have</span> <span class='id identifier rubyid_no'>no</span> <span class='id identifier rubyid_way'>way</span> <span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_pass'>pass</span> <span class='id identifier rubyid_descriptors'>descriptors</span> <span class='id identifier rubyid_into'>into</span> <span class='id identifier rubyid_a'>a</span> <span class='id identifier rubyid_new'>new</span> <span class='id identifier rubyid_process'>process</span> <span class='id identifier rubyid_that'>that</span> <span class='id identifier rubyid_is'>is</span> <span class='id identifier rubyid_exposed'>exposed</span> <span class='id identifier rubyid_to'>to</span> <span class='const'>Ruby</span>. <span class='const'>Also</span><span class='comma'>,</span> <span class='id identifier rubyid_cluster'>cluster</span> <span class='id identifier rubyid_mode'>mode</span> <span class='id identifier rubyid_is'>is</span> <span class='kw'>not</span> <span class='id identifier rubyid_supported'>supported</span> <span class='id identifier rubyid_due'>due</span> <span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_a'>a</span> <span class='id identifier rubyid_lack'>lack</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_fork'>fork</span>(<span class='int'>2</span>).
307<span class='op'>*</span> <span class='op'>**</span><span class='const'>Windows</span><span class='op'>**</span><span class='op'>:</span> <span class='const'><a href="Puma/Cluster.html" title="Puma::Cluster (class)">Cluster</a></span> <span class='id identifier rubyid_mode'>mode</span> <span class='id identifier rubyid_is'>is</span> <span class='kw'>not</span> <span class='id identifier rubyid_supported'>supported</span> <span class='id identifier rubyid_due'>due</span> <span class='id identifier rubyid_to'>to</span> <span class='id identifier rubyid_a'>a</span> <span class='id identifier rubyid_lack'>lack</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_fork'>fork</span>(<span class='int'>2</span>).
308<span class='op'>*</span> <span class='op'>**</span><span class='const'>Kubernetes</span><span class='op'>**</span><span class='op'>:</span> <span class='const'>The</span> <span class='id identifier rubyid_way'>way</span> <span class='const'>Kubernetes</span> <span class='id identifier rubyid_handles'>handles</span> <span class='id identifier rubyid_pod'>pod</span> <span class='id identifier rubyid_shutdowns'>shutdowns</span> <span class='id identifier rubyid_interacts'>interacts</span> <span class='id identifier rubyid_poorly'>poorly</span> <span class='id identifier rubyid_with'>with</span> <span class='id identifier rubyid_server'>server</span> <span class='id identifier rubyid_processes'>processes</span> <span class='id identifier rubyid_implementing'>implementing</span> <span class='id identifier rubyid_graceful'>graceful</span> <span class='id identifier rubyid_shutdown'>shutdown</span><span class='comma'>,</span> <span class='id identifier rubyid_like'>like</span> <span class='const'><a href="Puma.html" title="Puma (module)">Puma</a></span>. <span class='const'>See</span> <span class='id identifier rubyid_the'>the</span> [<span class='id identifier rubyid_kubernetes'>kubernetes</span> <span class='id identifier rubyid_section'>section</span> <span class='id identifier rubyid_of'>of</span> <span class='id identifier rubyid_the'>the</span> <span class='id identifier rubyid_documentation'>documentation</span>](<span class='id identifier rubyid_file'>file</span>.<span class='id identifier rubyid_kubernetes'>kubernetes</span>.<span class='id identifier rubyid_html'>html</span>) <span class='kw'>for</span> <span class='id identifier rubyid_more'>more</span> <span class='id identifier rubyid_details'>details</span>.</code></pre>
309<h2 id="Deployment">Deployment</h2>
310<ul>
311<li>
312<p>Puma has support for Capistrano with an <a href="https://github.com/seuros/capistrano-puma">external gem</a>.</p>
313</li>
314<li>
315<p>Additionally, Puma has support for built-in daemonization via the <a href="https://github.com/kigster/puma-daemon">puma-daemon</a> ruby gem. The gem restores the <code>daemonize</code> option that was removed from Puma starting version 5, but only for MRI Ruby.</p>
316</li>
317</ul>
318<p>It is common to use process monitors with Puma. Modern process monitors like systemd or rc.d
319provide continuous monitoring and restarts for increased reliability in production environments:</p>
320<ul>
321<li><a href="file.README.html">rc.d</a></li>
322<li><a href="file.systemd.html">systemd</a></li>
323</ul>
324<p>Community guides:</p>
325<ul>
326<li><a href="https://gist.github.com/anon987654321/4532cf8d6c59c1f43ec8973faa031103">Deploying Puma on OpenBSD using relayd and httpd</a></li>
327</ul>
328<h2 id="Community_Extensions">Community Extensions</h2>
329<h3 id="Plugins">Plugins</h3>
330<ul>
331<li><a href="https://github.com/harmjanblok/puma-metrics">puma-metrics</a> — export Puma metrics to Prometheus</li>
332<li><a href="https://github.com/yob/puma-plugin-statsd">puma-plugin-statsd</a> — send Puma metrics to statsd</li>
333<li><a href="https://github.com/sj26/puma-plugin-systemd">puma-plugin-systemd</a> — deeper integration with systemd for notify, status and watchdog. Puma 5.1.0 integrated notify and watchdog, which probably conflicts with this plugin. Puma 6.1.0 added status support which obsoletes the plugin entirely.</li>
334<li><a href="https://github.com/babbel/puma-plugin-telemetry">puma-plugin-telemetry</a> - telemetry plugin for Puma offering various targets to publish</li>
335<li><a href="https://github.com/anchordotdev/puma-acme">puma-acme</a> - automatic SSL/HTTPS certificate provisioning and setup</li>
336</ul>
337<h3 id="Monitoring">Monitoring</h3>
338<ul>
339<li><a href="https://github.com/ylecuyer/puma-status">puma-status</a> — Monitor CPU/Mem/Load of running puma instances from the CLI</li>
340</ul>
341<h2 id="Contributing">Contributing</h2>
342<p>Find details for contributing in the <a href="file.CONTRIBUTING.html">
342contribution guide</a>.</p>
343<h2 id="License">License</h2>
344<p>Puma is copyright Evan Phoenix and contributors, licensed under the BSD 3-Clause license. See the included LICENSE file for details.</p>
345<div id='footer'></div>
346</div> <!-- content  -->
347</div> <!-- y_main   -->
348</body>
349</html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.