Deploy Angular 5 application on Linux Server

12,769

Solution 1

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

Solution 2

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;
Share:
12,769
Gagan Jaura
Author by

Gagan Jaura

I have 9+ years of experience in .NET (ASP.NET, MVC, C#) and SQL server (SSRS, SSIS and BI). I have been working as Application Developer in .Net Technologies from 2006 and I have worked on ASP.NET, C#, MVC, WebAPI, AngularJS, SQL server, JQuery, LINQ, WCF, CSS and HTML.

Updated on June 05, 2022

Comments

  • Gagan Jaura
    Gagan Jaura almost 2 years

    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.

  • Gagan Jaura
    Gagan Jaura about 6 years
    I removed it but no luck :(
  • Gagan Jaura
    Gagan Jaura about 6 years
    There is no error in console. The browser is showing The page can't be displayed.
  • penleychan
    penleychan about 6 years
    You shouldn't remove the base... @GaganJaura, since your app is in a different folder path you should be using <base href="/folderPath">
  • Gagan Jaura
    Gagan Jaura about 6 years
    @penleychan I tried that too but did not work. I think that I need to open a port to listen so that I my app could run
  • penleychan
    penleychan about 6 years
    @GaganJaura, curious did you set up url rewrite?
  • Gagan Jaura
    Gagan Jaura about 6 years
    @nitishk72 The index.html file has basic stuff which is created by default. I have not touch it.
  • Gagan Jaura
    Gagan Jaura about 6 years
    @penleychan No. I did not.
  • nitishk72
    nitishk72 about 6 years
    @GaganJaura If you will remove that base tag then also it's fine because HTML by default start loading assets from current directory where HTML file is.
  • Gagan Jaura
    Gagan Jaura about 6 years
    I will try it tomorrow and will let you know.
  • Gagan Jaura
    Gagan Jaura about 6 years
    Where should I write these rules?