Last active
April 27, 2016 23:11
-
-
Save mikko/b7faa95a84cf0afec3f6 to your computer and use it in GitHub Desktop.
NodeJS production deploy to single server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sudo nginx -s restart ==> sudo nginx -s reload