- Change root password.
passwd root
- Follow steps Secure SSH
- Update Debian.
apt-get update && apt-get upgrade
- Install sudo.
apt-get install sudo
- Install dev tools (some npm packages need it).
apt-get install build-essential
- Choose language.
dpkg-reconfigure locales
and pick fr_FR.UTF-8 if you're french - Use UTC timezone
rm /etc/localtime
ln -s /usr/share/zoneinfo/UTC /etc/localtime
date
anddate -u
must have the same output
Don't forget to change andrea
and by your user's name.
- Add your user.
adduser andrea
- Add him to sudoers if needed.
usermod -G sudo andrea
- Find his public ssh key.
https://www.github.com/myuser.keys
orcat ~/.ssh/id_rsa.pub
- Add him to authorized keys (one per line).
vim ~/.ssh/authorized_keys
- Enable access without password to
wheel
group.visudo
:%sudo ALL = (ALL) NOPASSWD: ALL
- Prevent root connexion. Be sure you have another sudo user with ssh access.
vim /etc/ssh/sshd_config
&PermitRootLogin no
- Apply changes.
systemctl reload sshd
- Git.
apt-get install git
- Node & npm. (Be sure to use appropriate version)
curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
&sudo apt-get install -y nodejs
- Nginx.
apt-get install nginx
- MongoDB. (Be sure to use appropriate version)
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
apt-get install mongodb-org
- Add your website conf.
vim /etc/nginx/sites-available/mywebsite
- Enable it.
ln -s /etc/nginx/sites-available/th.conf /etc/nginx/sites-enabled/
- It default poses problem, remove it.
rm /etc/nginx/sites-enabled/default
- Restart Nginx to apply changes.
/etc/init.d/nginx restart
ouservice nginx restart
- Install PM2.
npm install pm2 -g
- Enable pm2's launch on system boot. Replace systemd by the one your OS uses, see PM2.
pm2 startup systemd
- Start app.
pm2 start /var/www/mywebsite/index.js -n mywebsite
- Save pm2 process list.
pm2 save
- https://certsimple.com/blog/deploy-node-on-linux
- http://nginx.org/en/docs/
- https://serversforhackers.com/nginx-caching
- http://blog.argteam.com/coding/hardening-node-js-for-production-part-2-using-nginx-to-avoid-node-js-load/
- https://gist.github.com/cosbynator/3072833
- https://github.com/aspnetde/ubuntu-nodejs-mongodb-guide