2017-04-11 90 views
1

我有一個簡單的網站,使用angular構建,我想在nginx上部署。在nginx上部署Angular網站

我已經安裝在我的電腦nginx和修改了根,如下nginx.conf文件的索引,

server { 
     listen  80; 
     server_name localhost; 

     #charset koi8-r; 

     #access_log logs/host.access.log main; 

     location/{ 
      root C:/Angular-Project/angular2-trial/src; 
      index index.html; 
     } 
     } 

沒有,當我訪問localhost,我得到的索引頁 - HTML內容,但它不能解決任何角度部分。並且在控制檯中沒有錯誤。

的Index.html

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Angular2Trial</title> 
    <base href="/"> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
</head> 
<body> 
    <app-root>Loading...</app-root> 
</body> 
</html> 

SRC - 文件夾結構: enter image description here

有沒有別的東西,我需要做的,使我的角度應用程序是功能?

回答

2

看看你的結構,你實際上並沒有創建一個構建。 好像你正在使用角度cli。

生成使用

ng build --base-href . 

產生DIST夾構建。保持在nginx中。 enter image description here

它的內容就是這樣。 enter image description here

而當你看看它的index.html應該是這樣的。

<!doctype html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>Angular2Liferay7</title> 
    <base href="."> 

    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="icon" type="image/x-icon" href="favicon.ico"> 
</head> 
<body> 
    <app-root>Loading...</app-root> 
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body> 
</html> 

注:如何pollyfills & main.bundle.js加載哪些不是在您的index.html。然後將加載Angular相關的東西。

+0

非常感謝...正如你所說,我確實忘記了建立。建設它解決了我的問題 – Vinay

+0

@Vinay:歡迎你:)你也可以upvote它:p –