简体   繁体   中英

Deploy Angular 5 application on Linux Server

I am new to deploying angular application on Linux, I used to do it on IIS which was pretty simple. I have a Linux server which I access through Putty. I want to deploy my angular 5 application on this server. I have performed following steps till now

  1. Run ng build --prod
  2. Copy the files in dist folder on one of the folder on linux server through pscp

Now, when I am trying to access the folder like http://hostname/folderPath/index.html , nothing comes up. I know I am missing some steps, could anyone please help me in deploying the application.

Just remove the base tag from index.html that's it

 <!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

After Removing Your code will like this

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

Based on our discussion you said you haven't set up URL rewrite rules.

Depending what you are using to host your application, you need to setup URL rewrite rules.

See official docs

For linux servers

Apache:

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

NGinx:

try_files $uri $uri/ /index.html;

不要删除“base href”它不起作用这样做对我有用:

<base href="" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM