USE This AUTO SCRIPT FOR UBUNTU 16.04
wget -O installer.sh https://raw.githubusercontent.com/cgidzinski/VPS-Start-Guide/master/installer.sh && bash installer.sh
VPS Start Guide (Manual)
By Colin Gidzinski
March 31/2017
EC2 Setup & Connection
- Launch EC2 Instance Ubuntu Server HVM
- Select size t2.micro (Free tier) or t2.nano
- If you want to change default storage type click next
- Create new SSH key pair (DONT LOSE THIS)
- Launch!
- Create Elastic IP and select the EC2 Instance you created earlier. (This gives you an ip address you can reassign from vps instance to instance)
EC2 Connection
Windows
- Run PuTTYgen to create a putty version of you key (Load key.pem, save as key.ppk)
- Input ubuntu@ElasticIPAddress as Host Name and under Connection>SSH>Auth Browse for the key.ppk
- Save and connect
Linux
- ssh -i test.pem ubuntu@ElasticIPAddress
FTP Setup
- sudo apt-get update
- sudo apt-get install vsftpd
- sudo nano /etc/vsftpd.conf
Uncomment
- write_enable=YES
- local_umask=022
- chroot_local_user=YES
Add
- allow_writeable_chroot=YES
- pasv_enable=Yes
- pasv_min_port=40000
- pasv_max_port=40100
- Sudo nano /etc/shells
Add
- /usr/sbin/nologin
- sudo service vsftpd restart
- sudo useradd -m john -s /usr/sbin/nologin
- sudo passwd john
- Open EC2 Security Groups
Add
- Custom TCP Rule 21 0.0.0.0/0
- Custom TCP Rule 40000-40100 0.0.0.0/0
9.Connect with username and password to IP on port 21
Domain Setup with Domain Host (Namecheap Etc.)
- Setup Email redirection if you want
- Setup DNS
Add
- A Record @ ElasticIP
- CNAME Record * domain.com
- CNAME Record www domain.com
DNS Propigation May Take Up To 48 Hours You can now use domain.com instead of your ElasticIP for FTP and PuTTY
NodeJS Setup
- sudo apt-get install python-software-properties
- curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
- sudo apt-get install nodejs
NGINX Setup
- sudo apt-get install nginx
- sudo systemctl start nginx
- Open EC2 Security Groups
Add
- HTTP
- HTTPS
SSL Setup
- cd
- sudo wget https://dl.eff.org/certbot-auto
- sudo chmod a+x certbot-auto
- ./certbot-auto certonly --standalone -d DOMAINNAME.com -d www.DOMAINNAME.com
- sudo openssl dhparam -out /etc/ssl/certs/DOMAINNAME.com.pem 2048
- cd ../../etc/nginx/sites-enabled
- sudo nano default
Delete Everything (Hold Ctrl+k) Add ** Replace DOMAINNAME.com with your domain name and PORT with your NODEJS Port **
server {
listen 80;
server_name DOMAINNAME.com www.DOMAINNAME.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
server_name DOMAINNAME.com www.DOMAINNAME.com;
ssl on;
# Use certificate and key provided by Let's Encrypt:
ssl_certificate /etc/letsencrypt/live/DOMAINNAME.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/DOMAINNAME.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/ssl/certs/DOMAINNAME.com.pem;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://localhost:8082;
proxy_read_timeout 90;
}
}
- sudo systemctl restart nginx
- Run every 90 days to renew ./certbot-auto renew --pre-hook "sudo systemctl stop nginx" --post-hook "sudo systemctl start nginx"
PM2 Setup
- sudo npm install pm2 -g
- pm2 startup
- sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu --hp /home/ubuntu
PM2 Setup (Run and Restart on Reboot and Errors)
- Go to your node project
- pm2 start server.js --name="PROJECT NAME"
- Use these to control
- Start: pm2 start PROJECT NAME
- Stop: pm2 stop PROJECT NAME
- Restart: pm2 restart PROJECT NAME
- Reset Counters: pm2 reset PROJECT NAME
- List: pm2 list
- Monitor: pm2 monit
- Delete: pm2 delete PROJECT NAME
- pm2 save
Misc
- Edit File: sudo nano filename
- Save File: Ctrl-x, Y, Enter
- Move Out Directory: cd ../
- Move Directory: cd directory
- List Directories: ls
- Git Clone: sudo git clone URL
- Git Pull: sudo git pull
- Autocomplete: [Tab]
- Paste: RightClick
- Copy: Highlight Text