環(huán)境介紹
- 服務(wù)器環(huán)境:ubuntu(16.04)64位
- 本地環(huán)境:windows10 64位
- 連接工具:mobaxterm
ubuntu安裝和基本配置
ecs阿里云買服務(wù)器惜索,購買的時(shí)候鏡像選擇ubuntu16.04极景,買的香港地區(qū)的不用備案,購買后本地打開終端妇汗,輸入root@xxx.xxx.xxx,然后輸入密碼廉油,連接遠(yuǎn)程服務(wù)器势誊,
- addgroup wmui添加用戶組
- useradd -d /home/wmui -s /bin/bash -m wmui創(chuàng)建wmui用戶
- passwd wmui設(shè)置密碼,如果忘記密碼唆貌,也可用此命令重置密碼
- usermod -a -G wmui wmui 添加用戶到組
- visudo 設(shè)置sudo權(quán)限
可以參考這篇文章 - root ALL=(ALL:ALL) ALL下面添加wmui ALL=(ALL) NOPASSWD: ALL
- ctrl+x保存退出
ssh無密碼登陸配置
首先你需要在本地安裝git并生成id_rsa.pub肄梨,打開命令行
- 在本地生成公鑰和私鑰:
ssh-keygen -t rsa -b 4096 -C "1719442545@qq.com"
在服務(wù)器生成公鑰和私鑰:
ssh-keygen -t rsa -b 4096 -C "1719442545@qq.com" - 在服務(wù)器窗口輸入:
echo "[your public key]" > ~/.ssh/authorized_keys將本機(jī)的公鑰拷貝到服務(wù)器的authorized_keys文件
完成以上操作,測(cè)試是否生效挠锥,重啟服務(wù):sudo service ssh restart新打開一個(gè)窗口众羡,輸入用戶名回車,登陸成功
nodejs環(huán)境搭建
- 安裝常用軟件
sudo apt-get install vim openssl build-essential libssl-dev wget curl git - nvm安裝
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
nvm install v8.9.1
nvm use 8.9.1
nvm alias default 8.9.1 默認(rèn)版本
安裝常用node包
npm i pm2 webpack vue-cli -g
nginx服務(wù)器代理設(shè)置
apt-get install nginx 通過nginx -v查看版本號(hào)
打開/etc/nginx/conf.d/文件夾蓖租,創(chuàng)建配置文件test-8081.conf粱侣,內(nèi)容如下:
upstream hello {
server 127.0.0.1:8081;
}
server {
listen 80;
server_name hello.86886.wang;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Nginx-proxy true;
proxy_pass http://hello;
proxy_redirect off;
}
}
- nginx -s reload 重啟服務(wù)器
阿里云服務(wù)器配置安全組(按自己的端口需求配置)
配置完后 在自己搭建的服務(wù)器上用pm2 啟動(dòng)node.js
pm2 start hello.js
pm2 list 查看啟動(dòng)的應(yīng)用
pm2 show hello 查看詳細(xì)信息
pm2 logs 查看當(dāng)前信息
pm2 stop hello 停止hello
pm2 delete hello 刪除hello