【问题标题】:How to deploy NodeJS Rest API in Ubuntu LTS 18 in apache2如何在 Apache2 的 Ubuntu LTS 18 中部署 NodeJS Rest API
【发布时间】:2018-11-05 09:52:11
【问题描述】:

我是 NodeJS 的新手,我有一个简单的网站,可以通过 Axios 将联系我们的信息从 ReactJS 发送到 NodeJS。

它正在我的本地机器上运行,我正在尝试将它部署在我的 AWS EC2 Ubuntu LTS 18 中。

我已经安装了 PM2,但我不知道下一步该做什么,我如何在安装了 Apache2 的 Ubuntu 中部署我的 NodeJS 并让它在我的服务器上运行,即使我关闭了我的终端。另外,API URL 端点是什么?

我希望有人可以帮助我在 Ubuntu 中部署这个基本的 nodejs。

【问题讨论】:

    标签: node.js ubuntu apache2 pm2 ubuntu-18.04


    【解决方案1】:

    你有两个问题:

    1. 将代码移动到服务器 - 您可以使用 shipit.js (https://github.com/shipitjs/shipit) 来执行此操作。看看这个关于shipit.js 和forever https://youtu.be/8PpBySjkWEM 的截屏视频,forever 类似于pm2。

    2. 将流量从 Apache 重定向到您的应用程序。它被称为reverse proxy。配置文件为:

    <VirtualHost *:80>
       DocumentRoot **where-your-app-public-files-are**
       ServerName **domain_name**
       ProxyRequests off
       ProxyPreserveHost on
       ProxyPass / http://127.0.0.1:**your-node-port**/
       ProxyPassReverse / http://127.0.0.1:**your-node-port**/
    </VirtualHost>
    

    **variables** 更改为您的数据。

    可能是这样的:

    <VirtualHost *:80>
       DocumentRoot /var/www/your-app
       ServerName your-domain-name.com
       ProxyRequests off
       ProxyPreserveHost on
       ProxyPass / http://127.0.0.1:4040/
       ProxyPassReverse / http://127.0.0.1:4040/
    </VirtualHost>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 2011-01-15
      • 2020-11-10
      • 2015-07-20
      • 2017-02-01
      • 1970-01-01
      相关资源
      最近更新 更多