motorscript.com

Nuxt.js Deployment Cheat-sheet

Published:

    Nuxt Deployment Cheatsheet

    1. Create a sudo user
    2. Harden SSH - https://gist.github.com/xtranophilist/174b08ab7c756afd56a4747acf64b878
    3. Cleanup

    Disable anacron:
    vi /etc/crontab
    Comment anacron lines
    http://bookofzeus.com/harden-ubuntu/disable-services/disable-anacron/

    curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
    sudo apt-get update
    sudo apt-get install nodejs npm

    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
    sudo apt-get update && sudo apt-get install yarn
    yarn --version

    yarn global add pm2

    If using different node versions in same server:
    Install nvm
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
    nvm install 12.8.0
    nvm use 12.8.0

    Setup pushing via Git
    app, repo, conf

    cd
    cd app
    yarn
    yarn build
    pm2 start npm – start
    OR
    pm2 start pm2.json
    pm2 status
    pm2 startup

    sudo apt-get install nginx

    cd
    cd conf
    vi nginx.conf

    server {
    listen 80;
    listen [::]:80;
    index index.html;
    server_name b1.edupatra.com;

    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;
    }
    

    }

    sudo ln -s /home/ep/conf/nginx.conf /etc/nginx/sites-enabled/edupatra.conf

    
           {
      "apps": [
        {
          "name": "thuprai",
          "instances": "max",
          "exec_mode": "cluster",
          "script": "npm",
          "args": "start",
          "cwd": "/home/thufx/app/",
          "env": {
            "HOST": "127.0.0.1",
            "PORT": "3000",
            "NODE_ENV": "production"
          }
        }
      ]
    }
    

    post-receive:
    #!/bin/bash
    git checkout -f
    cd /home/thufx/app/
    . ~/.nvm/nvm.sh
    nvm use 12.8.0
    yarn
    yarn build \
    && pm2 restart pm2.json

    Soft-link our configuration to nginx conf.d directory

    sudo ln -s /home/user/conf/nginx.conf /etc/nginx/conf.d/.conf

    Obtain SSL certificate with Certbot

    apt-get install software-properties-common
    add-apt-repository ppa:certbot/certbot
    apt-get update
    apt-get install python-certbot-nginx
    apt-get install python-certbot-nginx
    certbot --nginx
    

    Check configuration and restart nginx

    nginx -t
    systemctl restart nginx