Skip to content

Instantly share code, notes, and snippets.

@mikko
Last active April 27, 2016 23:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikko/b7faa95a84cf0afec3f6 to your computer and use it in GitHub Desktop.
Save mikko/b7faa95a84cf0afec3f6 to your computer and use it in GitHub Desktop.
NodeJS production deploy to single server
Sources:
===============
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-14-04
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04
https://github.com/yyx990803/pod
https://www.namecheap.com/support/knowledgebase/article.aspx/1162/46/how-can-i-point-my-domain-name-to-my-home-servers-ip
Basic setup
===============
% root access
ssh root@yourserverip
% create user 'web'
adduser web
% add to sudo group
gpasswd -a web sudo
% switch to new user
su web
% install node
% install POD (installs also pm2)
npm install -g pod
% add node application to POD
pod remote fancyApp https://github.com/username/fancyApp.git
% start application
pod start fancyApp
% install nginx
sudo apt-get update
sudo apt-get install nginx
% configure nginx to use reverse-proxy for port 80-> 8000
% insert in /etc/nginx/sites-available/default
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://APP_PRIVATE_IP_ADDRESS:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
% reload nginx configuration
sudo nginx -s restart
% configure yourdomain.com to point yourserverip via your domain provider
% application should now respond in http://yourdomain.com
Git hook for updating the application with git push
===============
% start pod web server
pod web
% add remote hook in github
http://github.com
-> Goto your repo
-> Settings
-> Webhooks & services
-> Add webhook (http://yourdomain.com:19999/hooks/fancyApp)
% TODO: monitoring with keymetrics or pm2-gui
% TODO: add other apps to the same server
% TODO: add example for url with auth
@joonaspessi
Copy link

sudo nginx -s restart ==> sudo nginx -s reload

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