search

Home  >  Q&A  >  body text

node.js - 终端 远程连接服务器,终端关闭后,服务器无法运行

我配置好服务器,上传node.js的express项目

远程使用iterm连接服务器
ssh root@xxxxxxxx
进入到express项目目录执行
npm start启动项目
终端显示启动 ./bin/www成功

打开外网网址
显示正常网址
但是当我关闭终端或者使用control+C退出的话
重新刷新网页,出现

请问大家是如何处理这个事情的,我远程启动了项目,但是我总不能一直在我这边开着这个终端吧

黄舟黄舟2876 days ago475

reply all(5)I'll reply

  • 迷茫

    迷茫2017-04-17 15:59:02

    nohup command &
    或者
    tmux
    Simply put, your program process is a child process of ssh, so when the parent process exits, the child process will also exit.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:59:02

    Recommended to usepm2或者forever

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 15:59:02

    Understand the principles of SIGHUP and learn to use one or more of nuhup/screen/tmux/service management (initd or systemd)

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:59:02

    When the terminal is closed, all processes belonging to it end. You can use pm2, or simply add &(with space)

    at the end

    reply
    0
  • PHPz

    PHPz2017-04-17 15:59:02

    Express has an advanced chapter, the address is here http://expressjs.com/zh-cn/ad..., you can use the process manager to close the terminal server and the nodejs project is still running, you can check it out

    reply
    0
  • Cancelreply