Skip to content

Commit 065b8e2

Browse files
committed
feat: configure Puma to use Unix socket for nginx communication
- Bind to /tmp/nginx.socket with umask=0077 (owner-only permissions) - Update Procfile to use bin/start-nginx wrapper - Only apply socket binding when DYNO env var present (Heroku)
1 parent c679b0f commit 065b8e2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
release: bundle exec rake db:migrate
2-
web: bundle exec puma -C config/puma.rb
2+
web: bin/start-nginx bundle exec puma -C config/puma.rb

config/puma.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,12 @@
2929
threads threads_count, threads_count
3030

3131
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
32-
port ENV.fetch("PORT", 3000)
32+
# On Heroku with nginx buildpack, bind to Unix socket instead of port
33+
if ENV["DYNO"]
34+
bind "unix:///tmp/nginx.socket?umask=0077" # Restrict socket permissions to owner only
35+
else
36+
port ENV.fetch("PORT", 3000)
37+
end
3338

3439
# Allow puma to be restarted by `bin/rails restart` command.
3540
plugin :tmp_restart

0 commit comments

Comments
 (0)