Serve Angular 6 App with nginx

Liron Hazan
Sep 9, 2018 · 1 min read

The easiest fastest way to start a demo environment when you have a CentOs vm somewhere inside the organisation domain which is just for your use and you’re too lazy to compose a docker image or to use docker due to security limitations..

Prerequisites:

  • install nginx
  • install github
  • checkout your project somewhere — I created a user
  1. Build the project to production as follows:
ng build --prod --base-href http://local-machine-ip/

2. Configure the nginx.conf server as follows:

server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /home/demo/ensilo-cloud-frontend/dist/ensilo-cloud-frontend;

# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;

location / {
try_files $uri $uri/ /index.html;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

3. Restart nginx: sudo systemctl restart nginx

BOOM that’s all :)

Liron Hazan

Written by

Mom gave *rock&roll* to yah — Senior Frontend Engineer@ SentinelOne | occasional Angular consultant..

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade