We deploy a Node.js project (Nuxt.js) based on VDS with Ubuntu Server OS

Good day, Khabrovites!





In this article, I will consider the issue of deploying from scratch a Nuxt.js project (or any other project on Node.js) on a VDS server using the Apahce2 web server, Node.js, pm2 process manager with a full installation cycle of all components.





Installation will be performed on a clean VDS server that does not have any settings.





The content of the article

Step 1. Connect via SSH to VDS

To connect to a VDS server via SSH, you no longer need to download and install any additional programs, since the OpenSSH client is already built into Windows PowerShell on the latest Windows 10 operating systems.





I will use the Windows Terminal application, which can be downloaded from the Microsoft Store (the developer of Windows Terminal is Microsoft itself).





Ubuntu Server 20.04





, :





ssh root@_IP_
      
      



root , .





IP- FQDN- , DNS A- IP- .





Command to connect to server via SSH
SSH

() :





Ubuntu Server Terminal
Ubuntu Server

, .





2. Apache2 -

- Apache2 , Ubuntu - Apache2.





:





apt install software-properties-common
      
      



Required package installation command

, :





Apache2 :





apt-add-repository ppa:ondrej/apache2
      
      



, , Enter:





, - Apache2:





apt install apache2
      
      



- Apache2. - Enter.





!





IP-, FQDN- , - Apache2 .





. 80 443 . - !





  Apache2
Apache2

3. Node.js (nvm) Node.js

NodeJS NodeJS. nvm.





GitHub.





Installing and Updating . wget:





     NVM     GitHub
NVM GitHub

:





wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
      
      



  NVM
NVM

Enter





, init 6







. SSH , 1.





1.





nvm , . NodeJS LTS:





  NodeJS LTS-
NodeJS LTS-

NVM " 2 " Node.js





Enter:





nvm install --lts
      
      



  NodeJS   NVM
NodeJS NVM

Node.js :





node -v
      
      



Node.js:





  NodeJS
NodeJS

4. pm2

, , Node.js, , Node.js, npm. pm2:





npm install -g pm2
      
      



:





   pm2
pm2

pm2 -h







5. Node.js- ( - Nuxt.js-)

Nuxt.js . Node.js-, , , .





. Nuxt.js , . ,





Nuxt.js - :





  • - npm run dev







  • - npm run start







static, npm run generate



. , Node.js





, pm2





pm2:





pm2 init
      
      



pm2
pm2

ecosystem.config.js



nano :





nano ecosystem.config.js
      
      



  ecosystem.config.js
ecosystem.config.js

Ctrl+O, Enter:





module.exports = {
  apps : [
    {
      name: "nuxt-dev",
      script: "npm",
      args: "run dev"
    },
    {
      name: "nuxt-prod",
      script: "npm",
      args: "run start"
    }
  ]
}
      
      



dev- :





pm2 start ecosystem.config.js --only nuxt-dev
      
      



prod-:





npm run build && pm2 start ecosystem.config.js --only nuxt-prod
      
      



, , Dev-:





 dev- NuxtJS-  pm2
dev- NuxtJS- pm2

/ . pm2:





pm2 start nuxt-dev
      
      



,





pm2 stop nuxt-dev 
      
      



.





NodeJS- pm2 :





pm2 status
      
      



- pm2
- pm2

:





pm2 monit
      
      



 pm2
pm2

pm2 :





pm2 startup
      
      



:





pm2 save
      
      



[] pm2

- pm2 pm2.io Bucket.





, Bucket ( . pm2).





-:





pm2 plus
      
      



pm2 , pm2.io ( y



Enter





   pm2.io?
pm2.io?

email .





, pm2 , Bucket - . TestBucket





 Bucket     - pm2
Bucket - pm2

Bucket - pm2 (). , :





- pm2
- pm2

pm2 :





pm2 unstartup
pm2 startup
pm2 save
      
      



  pm2
pm2

6. Node.js- Apache2 Proxy

Nuxt.js 3000 (-)





80 ( HTTP).





Apache2 Proxy:





a2enmod proxy_http
      
      



- :





systemctl restart apache2
      
      



  Apache2 Proxy HTTP
Apache2 Proxy HTTP

Apache2 :





cd /etc/apache2/sites-available
      
      



Apache2:





cp 000-default.conf _.conf
      
      



_.conf nano. :





  • ServerName: example.com





  • ServerAdmin: webmaster@localhost email





  • DocumentRoot: #





An example of a virtual host configuration file

, , :





ProxyPreserveHost On

ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
      
      



:3000 -





Ctrl+O Enter. Ctrl+Z





Port 3000 proxy
3000

-*:





a2ensite _
systemctl reload apache2
      
      



* a2ensite _









- - Apache2





7. pm2

, pm2 .





init 6



, .





- Node.js VDS-.





- Apache2, Node.js - NVM Node.js , Node.js- Vue.js- - Nuxt.js, pm2 .





, .





, ( ?) Docker NGINX. .





, - .





!








All Articles