1.進(jìn)入服務(wù)器,跟新服務(wù)器各種插件
sudo apt-get update
2.安裝響應(yīng)必要的組件
sudo apt-get install vim openssl build-essential libssl-dev wget git
3.服務(wù)器安裝nvm
在git中搜索nvm,然后找到 curl 或者 wget 如下:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
4.安裝好了之后 新打開一個新的命領(lǐng)行控制器,去node官網(wǎng)查看當(dāng)前node最新版,版本號 然后安裝nodejs
nvm install <node.js最新穩(wěn)定版版本號>
5.指定當(dāng)前服務(wù)器使用的node版本號
nvm use <nodejs版本號>
nvm alias default <nodejs版本號>
指定好了之后,能查看當(dāng)前nodejs版本號
node -v
6.安裝npm:
npm --registry=https://registry.npm.tobao.org install -g npm
7.執(zhí)行命令提升系統(tǒng)文件載入速度
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
8.安裝cnpm:
npm --registry=https://registry.npm.tobao.org install -g cnpm
9.安裝node環(huán)境常用的工具包
npm i pm2 webpack gulp grunt-cli -g
10.環(huán)境安裝完畢,測試下,創(chuàng)建一個文件app.js
vi app.js
文件寫入代碼
const http = require('http')
http.createServer(function(req, res){
res.writeHead(200,{'Content-Type':'text/plain'})
res.end('結(jié)束')
}).listen(8001)
console.log('開啟服務(wù)')
11.可以使用 pm2來運(yùn)行項(xiàng)目
pm2 start app.js
// 查看logs
pm2 logs
12.搭建Nagix
// 先關(guān)閉服務(wù) (如果沒有可以略過)
sudo service apache2 stop
// 刪除apache
update-rc.d -f apache2 remove
sudo apt-get remove apache2
// 跟新
sudo apt-get update
// 安裝nagix
sudo apt-get install nginx
// 進(jìn)入nginx文件夾
cd /etc/nginx/
// 進(jìn)入文件夾 con f.d
// cd conf.d