Skip to content

Instantly share code, notes, and snippets.

@sidkdbl07
Last active September 10, 2018 16:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sidkdbl07/3078febf42dfb6140272cf834db7bcd7 to your computer and use it in GitHub Desktop.
Save sidkdbl07/3078febf42dfb6140272cf834db7bcd7 to your computer and use it in GitHub Desktop.
Setup DigitalOcean droplet for meteor

Assumptions

  1. You have a DigitalOcean droplet (Ubuntu 16.04)
  2. You have a domain with an A name record pointed at the droplet HINT - whenever possible I point the nameservers at digital ocean's nameservers.

Create a droplet and user

Login to the servers

ssh -l root <your IP address>

Create a new sudo-enabled user

adduser <new username>
usermod -aG sudo <new username>

Exit and login with new user

exit
ssh -l <new username> <your IP address>

Install CertBot

sudo add-apt-repository ppa:certbot/certbot
sudo apt-get install python-certbot-nginx

Congure Nginx

sudo nano /etc/nginx/sites-available/default

Copy in the following, but leave all of the 'Managed by Certbot' lines:

map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
}

server_name example.com www.example.com;

location / {
                proxy_pass http://127.0.0.1:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade; #for websockets
                proxy_set_header Connection $connection_upgrade;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                #try_files $uri $uri/ =404;
        }

Then test the setup, and restart nginx if successful

sudo nginx -t
sudo systemctl reload nginx

Setup Firewall

sudo ufw enable
sudo ufw status
sudo ufw app list
sudo ufw allow 'Nginx Full'
sudo ufw allow OpenSSH
sudo ufw status

should see

Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
Nginx Full                 ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Nginx Full (v6)            ALLOW       Anywhere (v6)

Get Certificate

sudo certbot --nginx -d example.com -d www.example.com

Exit and run

sudo nginx -t
sudo systemctl reload nginx

Setup Renewal

sudo crontab -e

enter the following

15 3 * * * /usr/bin/certbot renew --quiet

Setup Mongo

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update

sudo apt-get install -y mongodb-org
sudo nano /etc/systemd/system/mongodb.service

Paste the following into the file

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

Then run the server

sudo systemctl start mongodb
sudo systemctl status mongodb
sudo systemctl enable mongodb

Configure Mongo

mongo
> use admin
> db.createUser(
   {
    user: "myUserAdmin",
    pwd: "abc123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
   }
  )
> quit()
mongo -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"

use myNewDatabase
db.createUser(
  {
    user: "myTester",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "myNewDatabase" } ]
  }
)

Install Forver

curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt-get install -y build-essential nodejs
sudo npm install -g forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment