【问题标题】:Deploying Angular Universal in Apache在 Apache 中部署 Angular Universal
【发布时间】:2019-10-02 02:53:44
【问题描述】:

我遇到了关于在 Apache 上部署 Angular ssr 的问题。

我相信,需要在 apache 上进行配置以及 .htaccess 文件。 以下是我浏览过的一些链接,但要么我无法配置,要么描述不够全面,无法实现。

https://github.com/angular/universal-starter/issues/514

Angular2 Universal deploy to apache remote server

How to properly launch Angular Universal to live server

How to deploy Angular Universal project to standard hosting?

我的问题是在 Apache 服务器上部署 Angular Universal,端口配置为 8080,并且在目录“custom”内 -- x.x.x.x:8080/custom

采取的步骤

1) 部署 dist/* 到 /var/www/html/custom

2) npm install 安装deps

3) pm2 启动 dist 文件夹下的 server.js

附上截图——

导航到 x.x.x.x:8080/custom 会给出目录结构。

我想我需要将请求重定向到以 PM2 启动的应用正在侦听的端口。

我关心的是怎么做

帮助非常感谢!!

【问题讨论】:

    标签: angular apache angular-universal


    【解决方案1】:

    我们使用pm2 ecosystem 指向本地主机

    首先在httpd.conf中启用mod_proxy和mod_proxy_http!

    如果您使用虚拟主机,请将以下代理设置添加到特定于域的主机文件中-

    ProxyPreserveHost On
    ProxyPass / http://localhost:4200/
    ProxyPassReverse / http://localhost:4200/
    

    重启你的 Apache 和 pm2

    因此,如果您访问您的实时域,例如 www.example.com 将由 pm2 通过 localhost:4200 提供服务

    【讨论】:

      【解决方案2】:

      您可以将 apache 服务器映射到 pm2 服务器:

      默认配置文件:/etc/httpd/conf/httpd.conf

      ProxyPass         /example  http://xx.xx.xx.xx:xx/
      ProxyPassReverse  /example  http://xx.xx.xx.xx:xx/
      

      这会将所有请求从 apache 服务器路由到您的 pm2 服务器

      【讨论】:

      • 如果我们添加 SSL 证书,它只适用于 http,然后它不会重定向到端口
      猜你喜欢
      • 2020-08-29
      • 2021-01-09
      • 2020-02-20
      • 1970-01-01
      • 2018-08-08
      • 2019-04-28
      • 2020-08-14
      • 1970-01-01
      • 2018-12-10
      相关资源
      最近更新 更多