2017-08-04 81 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

相關問題