A basic guide on how to deploy Nuxt.js Universal (SSR) app on a Vultr server.
-
Create new server Choose Cloud Compute
-
Server Location: Sydney
-
Server type: Debian 10 x64
-
Server Size: 25 GB SSD $5/mo
-
Add SSH key: In terminal
cat ~/.ssh/id_rsa.pub | pbcopy
and then select not to ask for password on login -
Deploy
- When it's done, you'll need to copy the server IP
- switch back to your terminal and run
ssh root@SERVER_IP
- replace
SERVER_IP
with whatever the ip is for examplessh root@45.63.31.54
- First thing, make sure the software is up to date
- Run
apt update
then - Run
apt upgrade
- Add security
- To protect your server from randoms brute force logging in run
apt install fail2ban
- Install Nodejs
- Run
apt install nodejs
- When that's done run
node -v
and check that it tells you a version, like10.x
Note: If modules dependencies require newer versions (i.e. 16.x.x of
node
usenvm
to download and managenode
: https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-debian-10
- Install Yarn
- Run
apt install yarnpkg
- Running
yarn -v
will throw error, that's because on debianyarn
is calledyarnpkg
so we'll fix that by linking it - Check where its install
which yarnpkg
should return:/usr/bin/yarnpkg
- run
ln -s /usr/bin/yarnpkg /usr/local/bin/yarn
that's saying to create ayarn
which links toyarnpkg
- if that worked, you can now try
yarn -v
and confirm it's working:1.13.0
Note: If using
nvm
installyarn
with the below: https://classic.yarnpkg.com/en/docs/install#debian-stable
- Install Git
- Run
apt install git
- In a local terminal window
cd ~/.ssh/
and look forconfig
nano config
and checkHost *
hasForwardAgent yes
:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
ForwardAgent yes
Host 68.183.104.106
ForwardAgent yes
This means that if you ssh
in to your server, you can access your github repo from there.
Note: Make sure your connecting to GitHub via SSH by running
ssh -T git@github.com
locally. If its denied make sure to add your SSH Key to Github first.
- Run
apt install apache2
Note: Apache isn't being used just yet we'll set apache up to connect your domain name and then proxy to your nuxt server
- Run
cd /var/www
which is kinda like your Sites directory - Run
git clone git@github.com:your_github_name/your_repo.git
for examplegit clone git@github.com:studiolathe/ebb-dunedin.git
- Don't forget to manually create your
.env
on the server
Note: If setting up staging branch, make sure to clone staging branch
git clone <url> --branch <branch> --single-branch [<folder>]
i.egit clone git@github.com:studiolathe/flavedo-albedo.git --branch staging --single-branch flavedo-albedo-staging
- Cd into the project and then run
yarn install
which will install all the project dependancies - Then we just
yarn run build
and thenyarn start --hostname 0.0.0.0
- In order to have the Nuxt server running in the background we need to add
yarn global add pm2
and then runpm2 start "yarn start --hostname 0.0.0.0"
Note: If setting up staging branch, make sure to run seperate PM2 instance
pm2 start "yarn start --hostname 0.0.0.0 --port 3001"
- Create a file in the root of your project call
scripts/deploy.sh
and add the below, be sure to change123.123.123.123
to the your server IP:
#!/usr/bin/env sh
USER=root
HOST=123.123.123.123
WEBROOT=/var/www/ebb-dunedin
ssh $USER@$HOST /bin/bash <<EOF
cd $WEBROOT
git fetch
git reset --hard origin/master
yarn install
yarn run build
pm2 restart all
EOF
- Make the script executable (in your command line)
chmod +x ./scripts/deploy.sh
- Create a file in the root of your project
nano /etc/apache2/sites-available/project-folder.conf
# Production
<VirtualHost *:80>
ServerName your-domain-name.com
ServerAlias www.your-domain-name.com
DocumentRoot /var/www/project-folder/dist
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>
# Staging
<VirtualHost *:80>
ServerName staging.flavedoandalbedo.com
ServerAlias www.staging.flavedoandalbedo.com
DocumentRoot /var/www/flavedo-albedo-staging/dist
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001/
</VirtualHost>
- Then enable with
a2ensite project-folder
- Setup proxies
a2enmod proxy proxy_http
- Restart server
systemctl restart apache2
- In the domain providers DNS, create a new
A
record and point it at the newIP
address and anotherA
record withwww
as host that points to@
6 Check updated DNS via https://www.whatsmydns.net/
Note: If reciving timeout errors it may be due to server firewalls. Run
apt purge ufw
and manage firewall via Vult UI.
- Add certbot
apt install -y python3-certbot-apache
- Then run
certbot --apache
- Tell it to get a cert for both www and the normal domain
- Say yes to enabling https redirect
- After pushing changes to git run
./scripts/deploy.sh
from the local project folder and watch it go!