Cheat-sheet: Nuxt.js Deployment with Git

    Download form data
  • Domain Name:
  • IP Address:
  • User on Server :
  • User Password : Regenerate Copy
  • SSH Port :
  • Project Name :
  • Use Firebase as CDN?
  • Manage multiple node versions on server with NVM?

Create a sudo user

useradd -m user
echo user:i9Hpd0t3N8T2Dp5| chpasswd
usermod -aG sudo user
chsh --shell /bin/bash user
su - user

Add user to /etc/ssh/sshd_config AllowUsers configuration line if AllowUsers is used to allow specific user logins via SSH.

Refer to Security: Hardening SSH on Linux Server for SSH Hardening cheatsheet.

Install node

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Install yarn and pm2

curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update && sudo apt install yarn
sudo yarn global add pm2
pm2 startup

Create pm2.json file in project root.

  "apps": [
      "name": "awecode",
      "instances": "max",
      "exec_mode": "cluster",
      "script": "npm",
      "args": "start",
      "cwd": "/home/user/app/",
      "env": {
        "HOST": "",
        "PORT": "3000",
        "NODE_ENV": "production"

Setup pushing via Git

mkdir repo.git app conf logs
cd repo.git
git init --bare
git --bare update-server-info
git config core.bare false
git config receive.denycurrentbranch ignore
git config core.worktree /home/user/app

cat > hooks/post-receive <<EOF
git checkout -f
cd /home/user/app
yarn build \
&& pm2 restart pm2.json

chmod +x hooks/post-receive
Add this bare repo as a remote on local.
git remote add server [email protected]:/home/user/repo.git/
ssh-copy-id [email protected]
git push server --all

Install and configure nginx

sudo apt-get install nginx
vim ~/conf/nginx.conf
#Redirect www to non-www
server {
    return 301 $scheme://$request_uri;

server {
    listen 80;
    listen [::]:80;
    index index.html;

    #access_log /home/user/logs/nginx.access.log;
    #error_log /home/user/logs/nginx.error.log;

    location /sitemap.xml {
      alias /home/user/sitemap.xml;

    location / {
      proxy_pass http://localhost:3000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Soft-link our configuration to nginx conf directory

sudo ln -s /home/user/conf/nginx.conf /etc/nginx/sites-enabled/awecode.conf

Obtain SSL certificate with Certbot

apt install certbot python-certbot-nginx
certbot --nginx

Check configuration and restart nginx

nginx -t
systemctl restart nginx