nodejs服務(wù)器部署

環(huán)境介紹

  • 服務(wù)器環(huán)境:ubuntu(16.04)64位
  • 本地環(huán)境:windows10 64位
  • 連接工具:mobaxterm

ubuntu安裝和基本配置

ecs阿里云買服務(wù)器,購買的時候鏡像選擇ubuntu16.04,買的香港地區(qū)的不用備案,購買后本地打開終端,輸入root@xxx.xxx.xxx,然后輸入密碼,連接遠程服務(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將本機的公鑰拷貝到服務(wù)器的authorized_keys文件

完成以上操作,測試是否生效,重啟服務(wù):sudo service ssh restart新打開一個窗口,輸入用戶名回車,登陸成功

nodejs環(huán)境搭建

nginx服務(wù)器代理設(shè)置

apt-get install nginx 通過nginx -v查看版本號
打開/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ù)器配置安全組(按自己的端口需求配置)

WechatIMG95.jpeg

配置完后 在自己搭建的服務(wù)器上用pm2 啟動node.js
pm2 start hello.js
pm2 list 查看啟動的應用
pm2 show hello 查看詳細信息
pm2 logs 查看當前信息
pm2 stop hello 停止hello
pm2 delete hello 刪除hello

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容