簡體   English   中英

在 Linux 服務器上部署 Angular 5 應用程序

[英]Deploy Angular 5 application on Linux Server

我是在 Linux 上部署 angular 應用程序的新手,我曾經在 IIS 上進行過,這非常簡單。 我有一個通過 Putty 訪問的 Linux 服務器。 我想在這台服務器上部署我的 angular 5 應用程序。 到目前為止,我已經執行了以下步驟

  1. 運行 ng build --prod
  2. 通過pscp將dist文件夾中的文件復制到linux服務器上的文件夾之一

現在,當我嘗試訪問像http://hostname/folderPath/index.html這樣的文件夾,什么也沒有出現。 我知道我遺漏了一些步驟,任何人都可以幫助我部署應用程序。

只需從index.html中刪除基本標記即可

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Angular App</title> <base href="/"> Some more code Don't do anything to this

刪除您的代碼后會像這樣

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Angular App</title> Some more code Don't do anything to this

根據我們的討論,您說您尚未設置 URL 重寫規則。

根據您用於托管應用程序的內容,您需要設置 URL 重寫規則。

查看官方文檔

對於 linux 服務器

阿帕奇:

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

金克斯:

try_files $uri $uri/ /index.html;

不要刪除“base href”它不起作用這樣做對我有用:

<base href="" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM