ryandotsmith / nginx-buildpack

Run NGINX in front of your app server on Heroku
457 stars 248 forks source link

Provide better support for local development #2

Closed ryandotsmith closed 9 years ago

ryandotsmith commented 11 years ago

I think this is a case of maintaining dev/prod parody. In production, the app server will be receiving requests from NGINX over a UNIX socket, it would be nice to have this work locally as well.

dominic commented 11 years ago

When setting this up on my application, I created a wrapper script to conditionally start my web server with or without nginx to prevent my team from having to manage two Procfiles.

Procfile:

web: bin/start

bin/start:

# Server command
COMMAND='bundle exec unicorn -p $PORT -c ./config/unicorn.rb'

if [[ $NGINX == "true" ]]
then 
  # Start command as argument to `start-nginx` script
  bin/start-nginx $COMMAND
else 
  # Start command without nginx (development and debugging)
  $COMMAND
fi

Once in production with the nginx-buildpack, I can control the use of nginx by setting the environment variable NGINX to trigger a restart:

heroku config:set NGINX=true
heroku config:unset NGINX