A Rails app needs an app server in front of Nginx, and the two real choices are Phusion Passenger and Puma. They occupy different operational shapes — Passenger is closer to PHP-FPM (Nginx integration, declarative config, multi-app support); Puma is closer to Gunicorn (per-app process you supervise yourself). This article walks through both, then helps you pick.
How to verify
Inspect what’s running today:
systemctl status puma-app 2>/dev/null | head
sudo nginx -T 2>/dev/null | grep -E 'passenger|puma|unicorn' | head
ls /etc/nginx/conf.d/*passenger* 2>/dev/null
sudo lsof -iTCP:3000 -sTCP:LISTEN 2>/dev/null
ps -eo pid,etime,cmd | grep -E "puma|passenger|unicorn" | head
If both Passenger and a Puma systemd unit appear, an in-progress migration was left half-done — pick one and remove the other before tuning.
What’s happening
Passenger is a hybrid Nginx module and standalone server. With the Nginx-integrated install, Nginx itself spawns Ruby workers through Passenger — the configuration is passenger_enabled on; in a server block plus passenger_app_root. Passenger manages its own process pool, exposes statistics, and handles multi-tenancy (multiple Rails apps on one Nginx instance share Passenger).
Puma is a pure Ruby app server with a primary process and worker children. It listens on a TCP port or UNIX socket, and Nginx connects to it like any HTTP upstream. Puma is what Rails generates by default since Rails 5. It is multi-process (workers) plus multi-threaded (threads); workers are forks of the master, threads share memory within a worker.
The shape of the workload changes which model wins. CPU-bound Rails apps benefit from more workers (and fewer threads), because the GVL serializes Ruby execution within a worker. I/O-bound Rails apps (lots of DB or external HTTP) benefit from more threads per worker, because threads pick up work while the GVL is released around I/O. The 5 workers × 5 threads default is a reasonable starting point but it is just a default.
Decision
-
Pick Puma if you have one Rails app per host, want full control of the systemd unit, or are following the Rails defaults. Most modern Rails deployments choose Puma.
-
Pick Passenger if you have multiple Rails apps on one host (it shares a process pool across them, smaller memory footprint), need the runtime stats dashboard, or already operate Passenger and have the staff comfort with it.
-
Configure Puma by editing
config/puma.rbin the Rails app:max_threads_count = ENV.fetch("RAILS_MAX_THREADS", 5).to_i min_threads_count = ENV.fetch("RAILS_MIN_THREADS", max_threads_count).to_i threads min_threads_count, max_threads_count workers ENV.fetch("WEB_CONCURRENCY", 4).to_i preload_app! bind "unix:///run/puma/app.sock" pidfile "/run/puma/app.pid" state_path "/run/puma/app.state" plugin :tmp_restart on_worker_boot do ActiveRecord::Base.establish_connection if defined?(ActiveRecord) endpreload_app!withon_worker_bootreconnecting AR is the standard pattern — saves memory via copy-on-write, but requires re-establishing per-worker resources. -
The systemd unit for Puma.
/etc/systemd/system/puma-app.service:[Unit] Description=Puma for app After=network.target [Service] User=deploy Group=www-data WorkingDirectory=/var/www/app/current RuntimeDirectory=puma Environment=RAILS_ENV=production ExecStart=/home/deploy/.rbenv/versions/3.3.6/bin/bundle exec puma -C config/puma.rb ExecReload=/bin/kill -USR1 $MAINPID KillMode=mixed Restart=on-failure [Install] WantedBy=multi-user.targetExecReload=/bin/kill -USR1is Puma’s phased restart signal — workers are recycled one at a time without dropping connections, but only ifpreload_app!is off. Withpreload_app!, onlyUSR2(full restart) works. -
Nginx in front, pointing at the Puma UNIX socket:
upstream puma_app { server unix:/run/puma/app.sock fail_timeout=0; } server { listen 443 ssl http2; server_name app.example.com; # ... ssl_certificate etc. root /var/www/app/current/public; try_files $uri @app; location @app { proxy_pass http://puma_app; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; } }Static files in
public/are served directly by Nginx — Puma never sees those requests.
Operational notes
- Puma’s
phased-restartonly works withoutpreload_app!. Without preload, each worker boot pays the full Rails boot cost (~5-10 s per worker) — that adds up if you have many workers, but the rolling restart is the trade-off. - Memory leaks in Rails are common (long-lived ActiveRecord connections, instance variables on singletons). Tools like
puma-killerandpuma_worker_killerrecycle workers at memory thresholds or request counts — analogous to PHP-FPM’spm.max_requests. - Passenger’s
passenger_min_instancesandpassenger_max_pool_sizeare the equivalents ofworkersin Puma. The big difference is Passenger spins up workers on demand and idles them down; Puma keeps the set you configured. - With both servers, the Rails connection pool (
pool: 5indatabase.yml) must be at least as large asthreadsper worker. Ifthreads = 5andpool = 3, threads will block waiting for connections under load. - Test the deploy with
kill -USR1 $MAINPID(phased) andkill -USR2 $MAINPID(full) once before relying on either in a real release script — Puma’s signal handling has changed across versions.
For the rbenv install backing this, see Installing Ruby with rbenv. Stack Harbor’s managed operations practice deploys Rails on Puma + Nginx as the default for single-app hosts, switching to Passenger only when multi-tenancy or staff familiarity dictates — the choice is about the operating shape, not which one is “better”.