Guide: Using NGINX as frontend webserver for MEAN

Introduction

MEAN serves its pages on port 3000 per default, the easiest way to use port 80 (http) or 443 (https) is to utilize NGINX, this will also allow you later down the road to use the power of NGINX cache, or load balancing.

 

Prerequisites

Ubuntu 16.04 server, and a MEAN stack installed. You can find a guide HERE, on how to install MEAN on Ubuntu 16.04

 

Step One – Installing NGINX

sudo apt install nginx

NGINX is now installed and you can find it on http://YOUR_SERVER_IP, however we need it to function as a proxy.

 

Step Two – Making NGINX work as a proxy

Open NGINX’s configuration file

sudo nano /etc/nginx/sites-enabled/default

Now find the location part of the configuration and insert the following line into the file as shown in the picture below

Note I’m using http://localhost:3000 since the NGINX application is on the same machine as the MEAN stack, change the IP to reflect your MEAN servers IP

proxy_pass http://localhost:3000;

Now just restart NGINX

sudo service nginx restart

Check that your server is redirecting by going to the address of your NGINX servers IP address.

You now have a working proxy server for your MEAN stack!

Leave a Reply