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 yourSiteNamee.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}
- In VPS:
- Reference
ufw
Enable ufw on ssh(22), http(80), https(443), 25(for SMTP)
- Usage:
- In VPS:
$ ./ufw.sh
- In VPS:
- Reference
nginx-ssh
- Setup nginx for the site
- add ssh cert(let's script) to the site
- renew the ssh cert automatically
- Prerequisites
- Already setup DNS record pointing to the server, use
dig ${domainName}to check - Put site files into
/var/www/{projectName}, refer to githubhook - Install Docker
- Install Docker-compose
- Install Nginx
- Run this tutorial to the step 3 or the process would fail because lacking of fullchain.pem
- Already setup DNS record pointing to the server, use
- Usage
- In VPS:
$ ./nginx-ssh.sh projectName projectDomain projectPortOnVPSe.g../nginx-ssh.sh pocket-watch pocket-watch.pro 4000 - Should be able to visit https://yoursite
- In VPS:
- 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