Skip to content

Commit 697d8c8

Browse files
committed
fix: Configure Puma to use Unix socket in production
- Production: bind to Unix socket (tmp/sockets/puma.sock) - Development/Test: bind to TCP port 3000 - Fixes "Address already in use" error on VPS deployment - Allows proper Nginx reverse proxy connection
1 parent a6505e4 commit 697d8c8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

config/puma.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
threads_count = ENV.fetch("RAILS_MAX_THREADS", 3)
2929
threads threads_count, threads_count
3030

31-
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
32-
port ENV.fetch("PORT", 3000)
33-
3431
# Allow puma to be restarted by `bin/rails restart` command.
3532
plugin :tmp_restart
3633

@@ -41,8 +38,11 @@
4138
# In other environments, only set the PID file if requested.
4239
pidfile ENV["PIDFILE"] if ENV["PIDFILE"]
4340

44-
# Production-specific configuration
41+
# Environment-specific configuration
4542
if ENV["RAILS_ENV"] == "production"
43+
# Production: Use Unix socket for Nginx reverse proxy
44+
bind "unix://#{ENV.fetch('PUMA_SOCKET', 'tmp/sockets/puma.sock')}"
45+
4646
# Run 2 worker processes for production
4747
workers ENV.fetch("WEB_CONCURRENCY", 2)
4848

@@ -61,4 +61,7 @@
6161
on_worker_boot do
6262
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
6363
end
64+
else
65+
# Development/Test: Use TCP port
66+
port ENV.fetch("PORT", 3000)
6467
end

0 commit comments

Comments
 (0)