通过PM2永久运行NodeJs http服务器 [英] Running NodeJs http-server forever with PM2

查看:696
本文介绍了通过PM2永久运行NodeJs http服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是关于结合PM2运行HTTP服务器.

My question is about running HTTP-server in combination with PM2.

我面临的问题是:

  1. HTTP服务器需要输入一个文件夹(该文件夹是网站的根目录)和一个端口号来运行网站.
  2. 即使使用-g选项安装了HTTP-server,PM2也无法识别HTTP-server命令.

因此,我尝试了以下操作(请注意,双破折号应将参数传递给HTTP服务器脚本:

So i tried the following (note the double dash which should pass the parameters to the HTTP-server script:

/node_modules/http-server/lib$ pm2 start http-server.js -- /home/unixuser/websiteroot -p8686

但这是行不通的.

我也尝试过:

http-server /home/unixuser/websiteroot -p8686

哪个可以正常工作,但是没有pm2的强大支持?

Which does work, but doesn't have the great support of pm2 ?

任何建议都会很棒,谢谢!

Any suggestions would be great, thanks!

推荐答案

您几乎拥有它.

通过执行以下操作检查http服务器的位置:

Check where http-server is located by executing:

$ which http-server

您应该得到这样的/usr/bin/http-server

然后cd到要为其提供文件并执行的目录:

Then cd to the directory you want to serve files from and execute:

$ pm2 start /usr/bin/http-server --name my-file-server -- -p 8080 -d false

--name my-file-server是可选的,但需要--才能将参数传递给http-server命令.

--name my-file-server is optional, but -- is required to pass arguments through to the http-server command.

这篇关于通过PM2永久运行NodeJs http服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆