Report this

What is the reason for this report?

How do I setup the mean stack for production

Posted on September 15, 2015

Hi guys, I’m new to this. It’s a two part question.

Question 1: I currently have used the terminal to ssh into the droplet containing the MEAN stack. I went into /opt/mean/ and ran “grunt”. However once I close the terminal on my machine the website is no longer up. How do I leave running even when I exit the server?

Question 2: I have purchased a namespace and sorted out the DNS etc. However when I go to my domain it is on port 80, the MEAN stack is on port 3000. How should I fix this, should I change the MEAN port to 3000 or should I use nginx to reverse proxy.

Thank you for all help :)



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

just as an addition and since the information for the setup is a bit spread out over a few posts here is what worked for my MEAN-stack (using yum, assume sudo):

$ yum update
$ yum install nginx

In nginx.conf add

include /etc/nginx/sites-enabled/*;

in the http-block (usually located in /etc/nginx, $ vi nginx.conf ). Create the /sites-available and /sites-enabled directories under /etc/nginx:

$ mkdir sites-available
$ mkdir sites-enabled

Created the file domain in ./sites-available (content see above, like default). Link enabled:

$ ln -s /etc/nginx/sites-available/domain /etc/nginx/sites-enabled/domain

Then

$ setsebool -P httpol_can_network_connect true

Restart nginx (service…) or

$ systemctl restart nginx

Hi!

While this was asked a while ago, I believe the following information will be able to help future visitors who might be experiencing the same issue:

In order to bind a program to port 80 or any port under 1024, it needs to have root privileges. Running an app as root is most of the time a bad idea, so, what is usually done is running a reverse proxy such as nginx or HAProxy on port 80 that forwards all incoming requests to the MEAN app on port 3000.

First, install nginx:

sudo apt-get update
sudo apt-get install nginx

Then, replace the default server block in /etc/nginx/sites-available/default with the following:

server {
    listen 80;

    server_name example.com;

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

Finally, restart nginx:

sudo service nginx restart

nginx should now be listening on port 80 and forwarding all requests to the MEAN app that is running on port 3000.

If you’re running the app in production, you will need to set it up so that it automatically starts on boot and restarts when it crashes. Take a look at the Install PM2 and Manage Application with PM2 sections in the following tutorial:

How To Set Up a Node.js Application for Production on Ubuntu 14.04

One other option, which is true only if you’re running Ubuntu 15.04 or later, or different OSes that use systemd as the init service, would be creating a systemd service as described in this tutorial.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.