Deploy single page application Angular: 404 Not Found nginx Deploy single page application Angular: 404 Not Found nginx angular angular

Deploy single page application Angular: 404 Not Found nginx


for those not using a Staticfile might wanna try this.

I had the same problem with nginx serving angular.The following is the default config file, probably found somewhere in /etc/nginx/sites-available/yoursite

     location / {            # First attempt to serve request as file, then            # as directory, then fall back to displaying a 404.            try_files $uri $uri/ =404;    }

but what we acctually want is...

     location / {            # First attempt to serve request as file, then            # as directory, then redirect to index(angular) if no file found.            try_files $uri $uri/ /index.html;    }


In your nginx.conf file try using:

try_files $uri $uri/ /index.html;

instead of:

try_files $uri $uri/ =404;

That worked for me on Angular 5 project.


I finally found the answer:After I generated the dist folder.

  • I created a file called Staticfile and put it in the dist folder
  • I opened Staticfile & I added this line pushstate: enabled

pushstate enabled keeps browser-visible URLs clean for client-side JavaScript apps that serve multiple routes. For example, pushstate routing allows a single JavaScript file route to multiple anchor-tagged URLs that look like /some/path1 instead of /some#path1.