fix: only bind to Unix socket on Heroku with nginx buildpack#2642
Merged
Conversation
KimberleyCook
approved these changes
Jun 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
config/puma.rbwas checking for the presence ofconfig/nginx.conf.erbto decide whether to bind to a Unix socket or a TCP port. Since the nginx config file is committed to the repository, this check evaluated to true in all environments — including development — causing Puma to bind tounix:///tmp/nginx.socketinstead of a TCP port.This meant that running
bundle exec rails serverin development would listen on a Unix socket that is not accessible via a browser, breaking the local development workflow.Root cause
The condition was introduced in PR #2629 to support the
heroku-community/nginxbuildpack, which usesbin/start-nginxto launch nginx alongside Puma. The socket and/tmp/app-initializedsignal are only meaningful when that buildpack orchestrates the boot. However, checkingFile.exist?("config/nginx.conf.erb")as a proxy for "running under nginx" is unreliable because the file exists in development, CI, and everywhere the repo is cloned.Fix
Add a check for
ENV["DYNO"]before the socket binding. Heroku sets this variable on all dynos, making it a reliable signal that the nginx buildpack is actually in use.This preserves the nginx buildpack integration on Heroku while restoring the default TCP port binding in development and other non-Heroku environments.
Verification
bundle exec rails serverin development binds tohttp://localhost:3000