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
Step 2. Adding the Apache2 repository to the server and installing the web server
Step 3. Installing the Node.js version manager (nvm) and Node.js itself
Step 4. Installing the pm2 process manager
Step 5. Launching a Node.js application (in our case, a Nuxt.js application)
Step 6. Proxying a Node.js application via Apache2 Proxy
-
-
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- .
() :
, .
2. Apache2 -
- Apache2 , Ubuntu - Apache2.
:
apt install software-properties-common
, :
Apache2 :
apt-add-repository ppa:ondrej/apache2
, , Enter:
, - Apache2:
apt install apache2
- Apache2. - Enter.
!
IP-, FQDN- , - Apache2 .
. 80 443 . - !
3. Node.js (nvm) Node.js
NodeJS NodeJS. nvm.
Installing and Updating . wget:
:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
Enter
, init 6
. SSH , 1.
1.
nvm , . NodeJS LTS:
NVM " 2 " Node.js
Enter:
nvm install --lts
Node.js :
node -v
Node.js:
4. pm2
, , Node.js, , Node.js, npm. pm2:
npm install -g 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
ecosystem.config.js
nano :
nano 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-:
/ . pm2:
pm2 start nuxt-dev
,
pm2 stop nuxt-dev
.
NodeJS- pm2 :
pm2 status
:
pm2 monit
pm2 :
pm2 startup
:
pm2 save
[] pm2
- pm2 pm2.io Bucket.
, Bucket ( . pm2).
-:
pm2 plus
pm2 , pm2.io ( y
Enter
email .
, pm2 , Bucket - . TestBucket
Bucket - pm2 (). , :
pm2 :
pm2 unstartup pm2 startup pm2 save
6. Node.js- Apache2 Proxy
Nuxt.js 3000 (-)
80 ( HTTP).
Apache2 Proxy:
a2enmod proxy_http
- :
systemctl restart apache2
Apache2 :
cd /etc/apache2/sites-available
Apache2:
cp 000-default.conf _.conf
_.conf nano. :
ServerName: example.com
ServerAdmin: webmaster@localhost email
DocumentRoot: #
, , :
ProxyPreserveHost On ProxyPass / http://127.0.0.1:3000/ ProxyPassReverse / http://127.0.0.1:3000/
:3000 -
Ctrl+O Enter. Ctrl+Z
-*:
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. .
, - .
!