【问题标题】:Deploy angular-universal to apache server (Angular 9)将 angular-universal 部署到 apache 服务器(Angular 9)
【发布时间】:2020-08-29 17:44:54
【问题描述】:

在本地构建和运行 Angular Universal 之后,我正在尝试部署到 apache 服务器。我正在将 dist 文件夹移动到公共 html。

我运行node dist/server/main.js,它从端口 localhost:4000 开始,当我 curl localhost:4000 时,我得到了内容。

附言我也安装了 pm2,当我尝试 pm2 start dist/server/main.js 启动服务器但当我尝试 curl 它显示 Internal server error

我还编辑了 .conf 文件以代理到 localhost:4000:

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

当我尝试访问它时显示

虚拟主机文件

    DocumentRoot /var/www/domain/public/dist/browser

    <Directory /var/www/domain>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =domain [OR]
    RewriteCond %{SERVER_NAME} =domain
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

    ProxyPreserveHost On

    ProxyPass / http://localhost:4000/
    ProxyPassReverse / http://localhost:4000/

【问题讨论】:

  • 显示您的完整虚拟主机。 Root 设置不正确,应该设置为dist/browser。此外,Internal server error 是默认的 apache 错误页面。如果您需要帮助,您需要查看日志并指出真正的错误...
  • @David - 感谢您的参与。我用虚拟主机文件编辑了帖子

标签: angular apache ubuntu angular-universal


【解决方案1】:

由于我使用 Let's Encrypt CA,它会在 /etc/apache2/sites-available 中创建其 .conf 文件

yourdomain-le-ssl.conf

所以从yourdomain.conf 文件代理到 localhost:4000 不是正确的配置,从 yourdomain-le-ssl.conf 代理是正确的

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-19
    • 2019-10-02
    • 1970-01-01
    • 2018-08-08
    • 2019-04-28
    • 2021-05-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多