Angular 会话在 putty 会话超时后被终止

The Angular session is killed after the putty session timeout

我只是想 运行 Angular 永远 运行 直到我手动杀死它所以我只是使用下面的命令 运行 它作为 运行 中的服务=20=]箱子

 nohup ng serve --host {xyz.com} &

它将启动应用程序并 运行ning 并创建 nohup.out 文件,但是一旦 putty 超时,会话就会消失。

谁能指导我实现这个目标?

你不应该在生产中使用 ng serve,你需要做的是构建你的 Angular 应用程序并在真实服务器(如 nginx 或 apache)中使用类似 proxy_pass 的东西来告诉它为您的 Angular 静态应用程序文件(index.html + js 包)

您在 运行 服务器上 ng serve 的应用程序冒着很大的风险,因为它背后的 http 服务器不安全!

将 systemd 等生产就绪工具用于 运行 您的 nodejs 应用程序可能是个好主意 - 本手册可以提供帮助:

https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-1/

在你的情况下,如果你的 ng 应用程序保存在 /opt/app 目录中,单元文件将是这样的

[Unit]
Description=hello_env.js - making your environment variables rad
Documentation=https://example.com
After=network.target

[Service]
Environment=NODE_PORT=3001
Type=simple
User=ubuntu

Workdir=/opt/app
ExecStart=/usr/bin/node /opt/app/.bin/ng serve --host {xyz.com}

Restart=on-failure

[Install]
WantedBy=multi-user.target

在第二部分 (https://nodesource.com/blog/running-your-node-js-app-with-systemd-part-2/),他们解释了如何启动几个应用程序实例并在它们前面使用 nginx 作为负载均衡器和支持 HTTPS 的反向代理