簡體   English   中英

如何在專用服務器上運行節點js?

[英]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

以啟動,重新啟動和停止您的應用-系統啟動或關閉時也會自動發生。

有關更多信息,請參見以下答案:

您也可以為此使用systemd,但是存在一些差異,因為系統更加復雜並且經常導致一些問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM