如何在nginx或apache httpd中构建angular 4应用程序?

嗨,我正在尝试构建Angular 4应用程序,接下来的步骤如下 –

构建构建

在我的amazon ec2实例中,我运行的是apache.遵循的步骤 –

#!/bin/bash
yum install httpd -y
yum update -y
cp dist/* /var/www/html/
service httpd start
chkconfig httpd on

一切正常,但我的应用程序使用auth0进行身份验证,我看到他们回调到http:// ip / callback

我的申请表 – 404未找到.

app-problem

我尝试构建像ng build –base-href.它没有用!
请帮助我如何构建这个,请注意,当我在本地使用服务时,一切都很棒.但当我尝试部署到生产时,它给出了这个错误.我非常确定在构建应用程序时我正在做的事情.

我试过nginx docker容器,它给出了同样的错误.我的docker文件看起来像这样.

来自nginx
COPY dist /usr/share / nginx / html

> docker build -t ng-auth0-web-dev.
> docker run -d -p 8080:80 ng-auth0-web-dev

上面的docker文件有什么问题吗?

https://github.com/auth0-samples/auth0-angular-samples/tree/master/01-Login – 示例应用代码

07002 – No error in logs,that means auth0 is working fine but I am getting build error with angular.

确切的错误:

enter image description here

auth0 callback settings

更新 –

我也尝试过像这样的建筑 –
ng build –base-href http://34.213.164.54/
和ng build –base-href http://34.213.164.54:80/,但同样的错误.

所以问题是如何缩小到我如何构建Angular App

public handleAuthentication(): void {
    this.auth0.parseHash((err,authResult) => {
      if (authResult && authResult.accessToken && authResult.idToken) {
        window.location.hash = '';
        this.setSession(authResult);
          localStorage.setItem('email',profile.email);
          this.verticofactoryService.registerUser(u);
          this.router.navigate(['/home']);
        });



      } else if (err) {
        this.router.navigate(['/home']);
        console.log(err);
        alert(`Error: ${err.error}. Check the console for further details.`);
      }
    });
  }
最佳答案
Angular应用程序是使用简单的静态HTML服务器提供服务的理想选择.您不需要服务器端引擎来动态组合应用程序页面,因为Angular在客户端执行此操作.

如果应用程序使用Angular路由器,则必须将服务器配置为在被要求提供其没有的文件时返回应用程序的主机页面(index.html).

假设你的nginx服务器conf只是添加这样的东西. try_files $uri $uri / /index.html;

参考 – https://github.com/auth0-samples/auth0-angular-samples/tree/master/02-User-Profile

谢谢你JB Nizet,它终于工作了.

server conf

相关文章

文章浏览阅读3.7k次,点赞2次,收藏5次。Nginx学习笔记一、N...
文章浏览阅读1.7w次,点赞14次,收藏61次。我们在使用容器的...
文章浏览阅读1.4k次。当用户在访问网站的过程中遇到404错误时...
文章浏览阅读2.7k次。docker 和 docker-compose 部署 nginx+...
文章浏览阅读1.3k次。5:再次启动nginx,可以正常启动,可以...
文章浏览阅读3.1w次,点赞105次,收藏182次。高性能:Nginx ...