Mantra how-to guide

Use Nginx as reverse proxy for your Mantra project

A Node.js web application usually opens a port number > 1024. You need to redirect 80 (http) or 443 (ssl) to it in the deployment

A  A  A 

Generally, you define a port greater than 1024 in your Node.js web applications (web user interface, Rest APIs, etc), so, you have the same situation with Mantra.

In Mantra, you define the port to be open with "Port" property in your application section of mantraconfig.json, like in this example:

"mainsite": {
    "BaseUrl": "",
    "FrontendLocation": "mainsite",
    "NotFoundRedirect": "/404.html",
    "LandingView": "landing.landingview",
    "Port": 3092

So, when you deploy this site to production, you need somehow to redirect ports :80 or :443 to your application port :3092.

In Node.js community, this is usually done with a reverse proxy. Esencially, a reverse proxy is a web server you install that redirects all requests coming from :80 port to :3092 (following this example).

The web server used usually to perform this task y Nginx, but you can have others solutions out there. Nginx is a free powerful solution with many capatilities, one of them is to be used as reverse proxy.

You get a number of advantages using this solution: you can set static files to be sent in Nginx or install a DDoS solution in that layer or your project deployment architecture, among many others.

Esencially, to do this task with Nginx, you need to set a file to tell it that all requests coming from :80 should be redirected to :3092, like this:

server {
   listen 80;


   location / {
      proxy_pass http://localhost:3092;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded_Proto $scheme;
      proxy_buffering off;

This simple Nginx configuration file is just an example and can be configured with many other features.

Basically, this is the standar solution used in Mantra / Node.js solution when deployment your web applications.