如何在生产环境中在 Windows Server 上正确运行 NodeJs [英] How to properly run NodeJs on Windows Server in production

查看:82
本文介绍了如何在生产环境中在 Windows Server 上正确运行 NodeJs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了困难,试图让我的 NodeJS 脚本在 Windows Server 2012 上运行.或者更准确地说,是为了让它健壮.

I am having difficult times, trying to make my NodeJS scripts run on windows server 2012. Or more precisely, to make it robust.

我已经安装了 PM2,他很棒,还为 Windows 启动添加了服务,运行良好,但现在我发现了我无法解决的最大问题.当windows server 用户启动pm2 start 时,直接在server 上或者通过ssh,注销时,所有的pm2 脚本都没有了.我试图查看 pm2-windows-service 但这似乎不一致,当我重新启动服务时,它工作正常,但有时我需要手动重新加载 o 仅重新启动 1 个脚本,然后整个 pm2 脚本列表以某种方式分离或附加给用户,所以当我从服务器注销时,一切又消失了.

I have installed PM2, whic his great, also added service for windows startup which works fine, but now I found biggest issue I can't solve. When windows server user start pm2 start, directly on server or through ssh, when logging out, all pm2 scripts are gone. I've tried to look into pm2-windows-service but that seems inconsistent, when I restart service, it works fine, but sometimes I need to manually reload o restart only 1 script and then whole list of pm2 scripts gets somehow detached or attached to user, so when I log out from server it's all gone again.

我找不到在脚本上设置观察程序/自动重启的解决方案,并使它们作为服务运行,而不管用户是否登录/退出.

I can't find solution to have watcher/autorestart on scripts, and make them run as a service regardless of user being logged in/out.

windows 上运行多个 nodejs 脚本一定有解决方案吗?

There must be solution for running multiple nodejs scripts on windows ?

推荐答案

一旦你启动了你的 NodeJS 进程,你应该运行 pm2 save 命令.这样,您声明的脚本就会被保存.

Once you launch your NodeJS processes, you should run pm2 save command. That way, your stated scripts are saved.

您附加/分离的问题可能是由于服务环境变量中的相对路径配置造成的.尝试移动到绝对路径.

Your attached/dettached problems may be due a relative path configuration in the service env variables. Try moving to an absolute path.

注意:PM2 建议使用具有管理员权限的用户启动命令;否则可能会出现不一致.

Note: PM2 recommendation is to launch commands with an admin-privileged user; otherwise inconsistences may appear.

注意 (2):请记住,Windows 上的 PM2 存在一些问题.例如,如果您重新启动服务器,大多数情况下进程会从 pm2 ls 消失(他们指出 Windows 没有恢复已保存实例的功能).如果你保存了它们,pm2 resurrect 会恢复它们.

Note (2): Bare in mind that PM2 on Windows has some issues. For example, if you restart your server, most of the times processes dissapear from pm2 ls (they noted that Windows does not have the feature to restore saved instances). If you saved them, pm2 resurrect will restore them.

这篇关于如何在生产环境中在 Windows Server 上正确运行 NodeJs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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