by Thinkful


Heroku Buildpack: nginx

This buildpack was forked from but is taking a slightly different approach by now.

The basic idea:

  • Build nginx and dependencies from source
  • Install nginx inside the target app
  • Allow the target app to configure nginx operation.

The original repo was focused on running nginx AND another app server in the target dyno, and synchronizing start and exit for both. This version is for nginx alone, serving static content or proxying or whatever.


The versions of nginx, PCRE, and the "headers_more" module are configured in scripts/

  • NGINX Version: 1.6.2
  • PCRE Version: 8.36
  • HEADERS_MORE Version: 0.25

All are fetched from their authoritative homes (URLs configured in as well). Build is cached in the app cache so it should only compile nginx the first time you run it.


To create a new app using this buildpack, clone your app's repository and make sure you have a config/nginx.conf.erb. From within the clone:

   $ heroku create --buildpack
   $ git push heroku master

(heroku magically creates a remote called 'heroku')

You should see the buildpack download, build, and install nginx and its dependencies.

The built files will be cached by Heroku so it won't build every time you push a change to your app. To clear the cache and force a rebuild (say, for a new version of nginx) you can install the heroku-repo tool:

It adds a command to the heroku command line app to flush the buildpack cache:

   $ heroku repo:purge_cache --app <appname>

The file 'config/nginx.conf.erb' will be processed through erb to create nginx.conf. The only thing that erb is really getting you is the expansion of the PORT variable but that's necessary. If you want to change the buildpack to use something besides erb, look in bin/start-nginx and scripts/


  • Unified NXNG/App Server logs.
  • L2met friendly NGINX log format.
  • Heroku request ids embedded in NGINX logs.
  • Customizable NGINX config.


NGINX will output the following style of logs:

measure.nginx.service=0.007 request_id=e2c79e86b3260b9c703756ec93f8a66d

You can correlate this id with your Heroku router logs:

at=info method=GET path=/ request_id=e2c79e86b3260b9c703756ec93f8a66d fwd="" dyno=web.1 connect=1ms service=8ms status=200 bytes=21

Setting the Worker Processes

You can configure NGINX's worker_processes directive via the NGINX_WORKERS environment variable.

For example, to set your NGINX_WORKERS to 8 on a PX dyno:

$ heroku config:set NGINX_WORKERS=8

Customizable NGINX Config

You can provide your own NGINX config by creating a file named nginx.conf.erb in the config directory of your app. Start by copying the buildpack's default config file.

Customizable NGINX Compile Options

See scripts/ for the build steps. Configuring is as easy as changing the "./configure" options.


Bill Gribble


Copyright (c) 2014 Thinkful

Copyright (c) 2013 Ryan R. Smith

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.