Deploy Simple NodeJS App
Tips
clone debian master menjadi nodejs webserver, lalu rubah hostname menjadi node-js-webserver
useradmin@debianMaster:~$ su -
Password:
root@debianMaster:~# hostnamectl set-hostname node-js-webserver
root@debianMaster:~# nano /etc/hosts
Setting Repository
Setting seperti dibawah inideb http://deb.debian.org/debian bullseye main
deb-src http://deb.debian.org/debian bullseye main
deb http://security.debian.org/debian-security bullseye-security main
deb-src http://security.debian.org/debian-security bullseye-security main
deb http://deb.debian.org/debian bullseye-updates main
deb-src http://deb.debian.org/debian bullseye-updates main
deb http://deb.debian.org/debian bullseye-backports main
deb-src http://deb.debian.org/debian bullseye-backports main
Menginstall GIT
Menginstall Curl
Menginstall NodeJS
root@webserver-rehan:~# curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
root@webserver-rehan:~# echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
Install Apache2
Clone Repo dari Github
Install MySQL
Mengamankan Installasi MySQL
Enter current password for root (enter for none): (Masukkan Password Root)
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Konfigurasi NodeJS App
Import Database
Membuat User Mysql
MariaDB [(none)]> create user 'nodejs'@'%' identified by '1234';
MariaDB [(none)]> grant all privileges on *.* to 'nodejs'@'%';
MariaDB [(none)]> exit
Edit Koneksi Mysql di db.js
Menginstall Dependencies App NodeJS
Jalankan Aplikasi
Tes Akses Via Web Browser
Menjalankan Aplikasi di Background
Menginstall PM2
Konfigurasi PM2 pada Package Json
Menjalankan Kembali Aplikasi
Melihat list PM2
Tes Akses Aplikasi pada Web Browser
Setting DNS Server
root@node-js-webserver:~# cd ~
root@node-js-webserver:~# apt install bind9
root@node-js-webserver:~# cd /etc/bind
root@node-js-webserver:/etc/bind# nano named.conf.local
root@node-js-webserver:/etc/bind# cp db.local db.node
root@node-js-webserver:/etc/bind# nano db.node
Tes Akses APlikasi pada W3b Browser
Reverse Proxy
root@node-js-webserver:/etc/bind# cd /etc/apache2/sites-available/
root@node-js-webserver:/etc/apache2/sites-available# cp 000-default.conf node.conf
root@node-js-webserver:/etc/apache2/sites-available# a2enmod proxy rewrite
root@node-js-webserver:/etc/apache2/sites-available# nano node.conf
root@node-js-webserver:/etc/apache2/sites-available# a2ensite node.conf
root@node-js-webserver:/etc/apache2/sites-available# a2dissite 000-default.conf
root@node-js-webserver:/etc/apache2/sites-available# service apache2 restart
Tes Akses Kembali di Browser
Quote
Tugas Praktikum Mandiri!!!
- Deploy Aplikasi NodeJS dari github berikut https://github.com/hendisantika/nodejs-mysql-crud
- Setting DNS server dengan domain nodejs2.lan
- Jalankan app di port 3030
- Setting Apache Reverse Proxy agar dapat diakses tanpa menggunakan Port