Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fahimbabarpatel/af3887dd5897f4efa3d230737847adce to your computer and use it in GitHub Desktop.
Save fahimbabarpatel/af3887dd5897f4efa3d230737847adce to your computer and use it in GitHub Desktop.
Node.js setup with passenger-install-nginx-module

Follow Phusion Passenger URL for Ubuntu setup https://www.phusionpassenger.com/library/install/nginx/install/oss/trusty/ ( If in future above URL is not present then visit to Phusion Passenger site to select Ubuntu OS and futher instaltion steps.)

Install our PGP key and add HTTPS support for APT
  • sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 561F9B9CAC40B2F7
  • sudo apt-get install -y apt-transport-https ca-certificates
Add our APT repository
Install Passenger + Nginx
  • sudo apt-get install -y nginx-extras passenger

  • rvm sudo passenger-install-nginx-module

Open /opt/nginx/conf/nginx.conf in sudo edit mode and do below steps:-
  • Add passenger_nodejs below passenger_ruby in http block. Like below
  passenger_nodejs /home/ubuntu/.nvm/versions/v0.12.5/bin/node;
  In passenger_nodejs you need to pass output of "which node" command.
  • Comment all lines in first server block and add below lines in first server block.
           server_name localhost; # You can pass your domain URL.
           passenger_app_root /home/node_demo_app; # full path to node app directory
           passenger_enabled on;
           passenger_app_type node;
           passenger_startup_file server.js; # main file name which start http server
           root /home/node_demo_app/public;  # full path to node app till public directory

All setup done. Start your nginx sudo /opt/nginx/sbin/nginx and hit server IP("server_name" value).

For stopping server sudo killall nginx.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment