[英]how to run node js on dedicated server?
我正在做一个聊天应用程序,并将其集成到网站上。 当我在本地服务器上执行命令'node index.js'时,一切正常。 但是,当我尝试在专用服务器上安装节点js并尝试通过ssh执行命令“ nohup node index.js&”时,会显示以下消息。
nohup:忽略输入并将输出附加到`nohup.out'
我已经按照本站点中提到的方法在服务器https://www.a2hosting.com/kb/installable-applications/manual-installations/installing-node-js-on-managed-hosting-accounts上安装节点js
有人能帮助我吗?
首先,您需要以正确的方式安装Node。 我写了一篇关于它的教程: 如何在Linux上获得Node 6.7.0 (当然,您可以使用较新的版本,只需在命令中更改版本)。
基本上就是这样-将版本更改为您喜欢的版本:
# change dir to your home:
cd ~
# download the source:
curl -O https://nodejs.org/dist/v6.1.0/node-v6.1.0.tar.gz
# extract the archive:
tar xzvf node-v6.1.0.tar.gz
# go into the extracted dir:
cd node-v6.1.0
# configure for installation:
./configure --prefix=/opt/node-v6.1.0
# build and test:
make && make test
# install:
sudo make install
# make a symlink to that version:
sudo ln -svf /opt/node-v6.1.0 /opt/node
我建议从源代码构建Node并始终运行make test
但您也可以安装速度更快的二进制程序包-只需确保您了解路径和hashbang行的问题-并说明更多信息和更多安装选项在我的教程中 。
然后,您需要确保每次重新启动服务器时都启动您的应用程序。 如果可以的话,我建议您使用Upstart。
使用Upstart将类似的内容保存在/etc/init/YOURAPP.conf
:
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [06]
# If the process quits unexpectadly trigger a respawn
respawn
# Start the process
exec start-stop-daemon --start --chuid node --make-pidfile --pidfile /www/YOURAPP/run/node-upstart.pid --exec /opt/node/bin/node -- /www/YOURAPP/app/app.js >> /www/YOURAPP/log/node-upstart.log 2>&1
只是改变:
YOURAPP
为您自己的应用程序的名称 /opt/node/bin/node
到您的node
路径 /www/YOURAPP/app/app.js
到您的Node应用程序的路径 /www/YOURAPP/run
至您想要PID文件的位置 /www/YOURAPP/log
到您想要的日志位置 --chuid node
以与node
不同的用户身份运行, --chuid node
改为--chuid OTHERUSER
(确保添加名称来自上述--chuid
的用户)
使用/etc/init/YOURAPP.conf
,您可以安全地重新启动服务器并使应用程序仍在运行,您可以运行:
start YOURAPP
restart YOURAPP
stop YOURAPP
以启动,重新启动和停止您的应用-系统启动或关闭时也会自动发生。
有关更多信息,请参见以下答案:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.