简体   繁体   English

如何将nodejs webapp设置为服务?

[英]how to setup nodejs webapp as service?

I have nodejs installed, npm installed, modules installed, and my app codes. 我安装了nodejs,安装了npm,安装了模块,还有我的应用程序代码。 On my dev machine I simply type node app.js in my app folder to start the dev server, but now it's the time to deploy it to a real server I got problem. 在我的开发机器上,我只需在我的app文件夹中键入node app.js即可启动开发服务器,但现在是时候将它部署到真正的服务器上了。

  1. Where is the regular folder to place my app codes. 放置我的应用代码的常规文件夹在哪里。
  2. Which user should be use to run my nodejs app. 应该使用哪个用户来运行我的nodejs应用程序。 and how to make the user only have permission to execute app codes, and 80, 443, 843 ports. 以及如何使用户只有执行应用程序代码的权限,以及80,443,843端口。
  3. How to write the service script, and stop server by kill pid? 如何编写服务脚本,并通过kill pid停止服务器?

ports are determined by which port your app listens on. 端口由您的应用侦听的端口确定。 If you have physical access via ssh to a server and have root privileges etc then you can just treat it as a dev server. 如果您通过ssh对服务器进行物理访问并具有root权限等,那么您可以将其视为开发服务器。

I would recommend forever for keeping it running and maybe a writing a balancer to handle multiple node apps at once. 我会建议永远保持它运行,也许会写一个平衡器来同时处理多个节点的应用程序。

Permission handling has to be done based on connectivity. 权限处理必须基于连接进行。 A user connects to your service and you authenticate it for its permission levels. 用户连接到您的服务,并对其权限级别进行身份验证。 This is done by hand. 这是手工完成的。

The folder you place it is not very relevant. 您放置它的文件夹不是很相关。

If you have say a no.de server you can learn how to use their smart machines. 如果你说过no.de服务器,你可以学习如何使用他们的智能机器。 THere are similar guides for say the Amazon EC2. 这是亚马逊EC2的类似指南。

I recommend Monit with Upstart. 我推荐Monit和Upstart。 You can read about that solution here and here . 您可以在此处此处阅读该解决方案。 You can also make a simple load balancer in nginx. 您还可以在nginx中创建一个简单的负载均衡器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM