Skip to content

samuelgoldenbaum/heroku-ngnix-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

heroku-ngnix-nodejs

Example of setting up NGINX and Node.js within a Heroku dyno.

Sample application using Node.js (socket.io) and NGINX buildpack to enable NGINX as a reverse-proxy for your Node.js application. Follow the Heroku NGNIX buildpack installtion steps to add the buildpack to your application.

Setup

In summary you need to simply run the following from the Heroku CLI to create a new Heroku app and add the Node.js and NGNIX buildpacks:

$ heroku create
$ heroku buildpacks:add heroku/nodejs
$ heroku buildpacks:add https://github.com/heroku/heroku-buildpack-nginx
$ git add .
$ git commit -am "init"
$ git push heroku master
$ heroku logs -t

Key Points:

Your Node.js server must listen to the unix socket at /tmp/nginx.socket:

// listen to ngnix socket
server.listen('/tmp/nginx.socket', function () {
    console.info(`server up`);
});

and let NGNIX know you want to start listening by touch /tmp/app-initialized file:

const fs = require('fs');

// let ngnix know we want to start serving from the proxy
fs.openSync('/tmp/app-initialized', 'w');

The NGNIX config file is located in /config/nginx.conf.erb The nginx.conf.erb in the repo should have all you needed. In particular, pay attention to setting the upstream Node.js server:

upstream websocket {
    server unix:/tmp/nginx.socket fail_timeout=0;
}

and then specify that the http location section::

proxy_pass http://websocket;

About

Example of setting up ngnix and node in a dyno

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published