Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fahimbabarpatel/83a8bbf127c8df626994 to your computer and use it in GitHub Desktop.
Save fahimbabarpatel/83a8bbf127c8df626994 to your computer and use it in GitHub Desktop.
Node.js + Nginx + Passenger setup (Ubuntu)

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
Open /etc/nginx/nginx.conf in sudo edit mode and do below steps:-
  • Add passenger_nodejs in staring of 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.
  • Uncomment below line
include /etc/nginx/passenger.conf;
Open /etc/nginx/sites-available/default in sudo edit mode and do below steps:-
  • Remove below lines:-
	root /usr/share/nginx/html;
	index index.html index.htm index.nginx-debian.html;
        location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
  	        try_files $uri $uri/ =404;
        }
  • Add below lines inside 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. Restart your nginx sudo service nginx restart and hit server IP("server_name" value).

Thanks!

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