How to Deploy an Angular app in Production with Nginx

This tutorial I will show you Nginx installation and configuration steps to serve Angular application in production. I am gonna use Ubuntu 16.04 operating system.

How to Deploy an Angular app in Production with Nginx

Install and Configure Nginx for Angular

First update the apt-get package lists and then install Nginx using apt-get:

Then open the default file to configure server which is located in /etc/nginx/sites-available/ directory.

Delete everything in this configuration file and paste the following content:

To make the changes active, restart the web server nginx:

Now check the status of Nginx service by running following command, you should get “active” green color text along with other text.

How to Deploy angular app

Copy and move all the compiled files to webserver root folder,ex: /var/www/html.

For example, If you are using Angular CLI, then you should run below command to get compiled files for production:

When you run the ng build --prod command, it creates a /dist folder and it places all compiled files inside it. You have to move those files to web server root folder, ex: /var/www/html. Thant, it now you can access your application with your public IP or domain name.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

0 0 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Hasitha Kaushan
Hasitha Kaushan
2 years ago

It was really helpfull. Thanks soo much 😀 Saved my day xD

Satyam ()
Satyam ()
2 years ago

When I closing my ssh window, server is throwing 404 error. How can I keep running the nginx continuously?

2 years ago
Reply to  Satyam ()

You don’t have do anything special, will run as service in the background. Protection Status
Would love your thoughts, please comment.x