2017-08-04 76 views
6

您好我想建立的角4应用程序,步骤,其次是低于 -如何在nginx或apache httpd中构建角度为4的应用程序?

构建ng build

在我运行的Apache我的Amazon EC2实例。随后的步骤 -

#!/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 .,它没有工作! Please help me how to build this one, please note that when I use纳克serve`在我的本地一切工作真棒。但是当我尝试将其部署到生产中时,会出现此错误。我非常确定在构建应用程序时我正在做错的事情。

我试过nginx码头集装箱,它给出了同样的错误。我的码头文件看起来像这样。

FROM nginx COPY dist /usr/share/nginx/html

  1. 搬运工构建-t NG-auth0-web开发。
  2. 搬运工运行-d -p 8080:80 NG-auth0-web开发

什么不对上述搬运工文件?

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

https://manage.auth0.com/#/logs - 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/,但是同样的错误。

所以问题缩小到我如何建立角应用

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.`); 
     } 
    }); 
    } 
+0

为什么你期望的请求/回调给予比404其他什么吗?您是否配置了Apache来为该URL提供任何内容? –

+0

是的,我正在请求/ /回调将验证用户。我没有在apache中配置任何东西。没有别的,我遵循上述步骤。你可以给我一个例子吗 ? – irobo

+0

一个什么样的例子?当/ callback请求到达服务器时应该发生什么? –

回答

4

角的应用程序是一个简单的静态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

相关问题