Kami menerapkan proyek Node.js (Nuxt.js) berdasarkan VDS dengan OS Server Ubuntu

Selamat siang, orang Khabrov!





Pada artikel ini, saya akan mempertimbangkan masalah penerapan dari awal proyek Nuxt.js (atau proyek lain di Node.js) pada server VDS menggunakan server web Apahce2, Node.js, manajer proses pm2 dengan siklus instalasi penuh dari semua komponen.





Penginstalan akan dilakukan di server VDS bersih yang tidak memiliki pengaturan apa pun.





Isi artikel

Langkah 1. Hubungkan melalui SSH ke VDS

Untuk terhubung ke server VDS melalui SSH, Anda tidak perlu lagi mengunduh dan menginstal program tambahan apa pun, karena klien OpenSSH sudah ada di dalam Windows PowerShell pada sistem operasi Windows 10 terbaru.





Saya akan menggunakan aplikasi Terminal Windows, yang dapat diunduh dari Microsoft Store (pengembang Terminal Windows adalah Microsoft sendiri).





Ubuntu Server 20.04





, :





ssh root@_IP_
      
      



root , .





IP- FQDN- , DNS A- IP- .





Perintah untuk terhubung ke server melalui SSH
SSH

() :





Terminal Ubuntu Server
Ubuntu Server

, .





2. Apache2 -

- Apache2 , Ubuntu - Apache2.





:





apt install software-properties-common
      
      



Perintah instalasi paket yang diperlukan

, :





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





Contoh file konfigurasi host virtual

, , :





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