The scripts I used for setting up VPS on Digital Ocean
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
githubhook.sh
nginx-ssh.sh
ufw.sh

README.md

vps-setting

The scripts I used for setting up VPS(Droplet) on Digital Ocean

Ubuntu

githubhook

Enable pushing code from local to vps

  • Prerequisites
  • Usage:
    • In VPS: $ ./githubhook.sh yourSiteName e.g. ./githubhook.sh pocket-watch
    • In local repo: $ git remote add server ${address is the output from previous command}
    • In local repo: $ git push server master
    • In VPS, find repo in /var/www/${yourSiteName}
  • Reference

ufw

Enable ufw on ssh(22), http(80), https(443), 25(for SMTP)

nginx-ssh

  1. Setup nginx for the site
  2. add ssh cert(let's script) to the site
  3. renew the ssh cert automatically
  • Prerequisites
    1. Already setup DNS record pointing to the server, use dig ${domainName} to check
    2. Put site files into /var/www/{projectName}, refer to githubhook
    3. Install Docker
    4. Install Docker-compose
    5. Install Nginx
    6. Run this tutorial to the step 3 or the process would fail because lacking of fullchain.pem
  • Usage
    • In VPS: $ ./nginx-ssh.sh projectName projectDomain projectPortOnVPS e.g. ./nginx-ssh.sh pocket-watch pocket-watch.pro 4000
    • Should be able to visit https://yoursite
  • Reference

(For cominsoon.io, I setup a simple nginx server config for cominsoon.io and run sudo certbot --nginx -d cominsoon.io -d www.cominsoon.io first, or the process failed because lacking of fullchain.pem, maybe I need to add this part to the shell script next time, see the 6 in Prerequisites)

Troubleshooting for ridiculous deploying issues

Issues I met that hard to be found on google(or it took me long to google)

Unable to install gem nokogiri on ubuntu VPS

I was using docker, I didn't meet the problem when running docker-compose on my local Mac machine, but it always failed on my ubuntu VPS, here's a piece of my Dockerfile to solve the problem

RUN bundle config build.nokogiri --use-system-libraries && \
    gem install bundler
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN gem install nokogiri -- --use-system-libraries && \
    bundle install

Failed to execute bundle install on VPS

The only ridiculous gem in Ruby world is nokogiri, so you should think about other aspects instead of the gem itself when there's an error happen to bundle install.

I was deploying a node project and a rails project on a same VPS, it is a Ubuntu 16.04 with 512MB memory and 20G disk. I failed to run bundle install because I lack of memory space. And I added swap to solve this problem