Nous déployons un projet Node.js (Nuxt.js) basé sur VDS avec Ubuntu Server OS

Bonne journée, Khabrovites!





Dans cet article, j'examinerai la question du déploiement à partir de zéro d'un projet Nuxt.js (ou de tout autre projet sur Node.js) sur un serveur VDS utilisant le serveur Web Apahce2, Node.js, gestionnaire de processus pm2 avec un cycle d'installation complet de tous les composants.





L'installation sera effectuée sur un serveur VDS propre qui n'a aucun paramètre.





Le contenu de l'article

Étape 1. Connectez-vous via SSH à VDS

Pour vous connecter à un serveur VDS via SSH, vous n'avez plus besoin de télécharger et d'installer des programmes supplémentaires, car le client OpenSSH est déjà intégré à Windows PowerShell sur les derniers systèmes d'exploitation Windows 10.





J'utiliserai l'application Windows Terminal, qui peut être téléchargée depuis le Microsoft Store (le développeur de Windows Terminal est Microsoft lui-même).





Ubuntu Server 20.04





, :





ssh root@_IP_
      
      



root , .





IP- FQDN- , DNS A- IP- .





Commande pour se connecter au serveur via SSH
SSH

() :





Serveur Terminal Ubuntu
Ubuntu Server

, .





2. Apache2 -

- Apache2 , Ubuntu - Apache2.





:





apt install software-properties-common
      
      



Commande d'installation de package requise

, :





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: #





Un exemple de fichier de configuration d'hôte virtuel

, , :





ProxyPreserveHost On

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



:3000 -





Ctrl+O Enter. Ctrl+Z





Proxy du port 3000
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