Deploy meteor app with pm2-meteor, nginx, free https(Let's Encrypt) instead of mup(mupx) or galaxy

[Mobile version(QRCode)] Total views:65,879 / Applauds for blog:1
Welcome to my page. I am an adminisrator of this site.
If you are this db's user, please contact with me by private mail. If not, please contact with me by email or twitter or facebook
Access record[Graph / PV Info.(Past 1 day / Past 1 week) / Access from outside (Yesterday / Past 1 week) / Vistors's list]
ProfilePmail(Mail)
Inbox   /Send   /Sent
Reviews(List   /Limit)
Poll   /Agree:Got   /Sent
Fan
Works/Music
Blog
[Write]
Links
My Play List
<=Newer article Dance studio (school) in KL
=>Older article Useful libraries of react

1.
2017/08/13 (Updated 2018/03/03) "Meteor > Deploy meteor app with pm2-meteor, nginx, free https(Let's Encrypt) instead of mup(mupx) or galaxy"
[Show only this article / Modify / Delete / Send trackback / Add to the shared category]

1. Background
2. Install meteor app on remote server
    1. About reference
    2. Choose VPS or some cloud environment using pm2-meteor
    3. Preparation on remote Linux
    4. Preparation on Client side
3. Set up SSL Certificate (HTTPS) using Let's encrypt
    1. Reference
    2. Procedure on remote server
4. Set up nginx
5. If you want to move your local mongo db's content to remote server

1. Background


mup (mupx)
https://github.com/zodern/meteor-up
was popular tool to deploy meteor to deploy to your own environment, if you are not using galaxy.

But I encountered problems when I used them with meteor 1.5.x and it was hard to solve just using the tool.
Meteor's deployment was so easy beforehand but now it becomes hard while I haven't touched it for a while, 
Probably it is due to the lack of power for non-commercial deployment way due to the effort of monetization for galaxy (Galayx is easy to use actually if you don't mind so much about money).

Anyway after some struggles, I succeeded in deploying without them with HTTPS support in another way.
I will share how I did it.
2. Install meteor app on remote server


    1. About reference

I used pm2-meteor for this.
https://www.npmjs.com/package/pm2-meteor
    2. Choose VPS or some cloud environment using pm2-meteor

VPS is cheap and worthwhile consideration if you are paying from you personal budget.
I chose ConoHa for it instead of Vultr or Digital Ocean this time.
    3. Preparation on remote Linux

This is the case on CentOS 7.3
yes | yum install epel-release --enablerepo=epel;
yes | yum install nodejs --enablerepo=epel;
yes | yum install npm --enablerepo=epel;
yes | npm install pm2 -g --enablerepo=epel;
yes | yum install gcc-c++;

# On Amazon Linux, you have to update node.js's version
sudo yum install nodejs npm --enablerepo=epel;

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

. ~/.nvm/nvm.sh

nvm install 4.6.1


If you want to install mongodb-server on same remote linux, refer to the official document to install latest one.
https://docs.mongodb.com/manual/installation/
    4. Preparation on Client side

# On client machine
npm i -g pm2-meteor;

#In the case of project "vps-ranking"
#In meteor's PJ folder
mkdir .deployment;
cd .deployment;
pm2-meteor init;

#Confirm the content of pm2-meteor.json and edit it if necessary
vi pm2-meteor.json
{
  "appName": "vps-ranking",
  "appLocation": {
    "local": "../"
  },
  "meteorSettingsLocation": "../vps-ranking-settings.json",
  "meteorSettingsInRepo": false,
  "prebuildScript": "",
  "meteorBuildFlags": "--architecture os.linux.x86_64  --server-only",
  "env": {
    "ROOT_URL": "http://vps-ranking.com/",
    "PORT": "3020",
    "MONGO_URL": "mongodb://localhost:27017/vps-ranking"
  },
  "server": {
    "host": "vps-ranking.com",
    "username": "root",
    "deploymentDir": "/opt/meteor-apps",
    "loadProfile": "",
    "nvm": {
      "bin": "",
      "use": ""
    },
    "exec_mode": "cluster_mode",
    "instances": "1",
    "pem": "~/.ssh/id_rsa"
  }
}

pm2-meteor deploy;
pm2-meteor start
pm2-meteor status
pm2-meteor logs
I used port 3020 because I would use nginx for HTTPS

And when you are running the process, log in the server and type the following command to make script run after restarting of the server.
pm2-meteor startup;
pm2-meteor save;

3. Set up SSL Certificate (HTTPS) using Let's encrypt


    1. Reference

https://github.com/nolandg/meteor-lets-encrypt
    2. Procedure on remote server

yes | yum install nginx;
yes | yum install certbot;

wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto;
./certbot-auto;

# If you want to define for multiple domains, as example
./certbot-auto -d vpsranking.com -d en.vpsranking.com -d cn.vpsranking.com -d vps-ranking.com

# Set updating of SSL certificate in cron
crontab -e
00 1 * * 1 . ~/.bash_profile;/root/certbot-auto renew > /var/log/letsencrypt-renewal.log

# If firewall is stopping the access to port 443, you have to open
firewall-cmd --add-service=http --zone=public --permanent
firewall-cmd --add-service=https --zone=public --permanent
firewall-cmd --reload

4. Set up nginx

yum install nginx;
# edit server name
vi /etc/nginx/nginx.conf

# Insert the line into nginx's config from let's encrypt getting the help of the command though we will confirm and edit later
git clone https://github.com/letsencrypt/letsencrypt;
cd letsencrypt/;
./letsencrypt-auto --nginx;

# After it, edit config nginx referencing set lines
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;
    gzip  on;

    server {
        listen       80;
        server_name  vpsranking.com;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/vpsranking.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/vpsranking.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        
        server_name  vpsranking.com;
        location / {
            proxy_pass http://vpsranking.com:3020;
         #   proxy_http_version 1.1;
         #   proxy_set_header Upgrade $http_upgrade; #for websockets
         #   proxy_set_header Connection "upgrade";
         #   proxy_set_header X-Forwarded-For $remote_addr; <= I found these from examples but for some reason this line caused infinitive redirecting loop, so I couldn't use this line
         #   proxy_set_header Host localhost; #  $host;
         }
    }
}

Then start nginx
systemctl start nginx;
chkconfig nginx on;

5. If you want to move your local mongo db's content to remote server

Example on client
mongodump --db vpsranking
scp -Cpr dump $USER@vpsranking.com:~/

Example on server side
mongorestore dump


Add comment to this article


[Read other articles]
<=Newer article Dance studio (school) in KL
=>Older article Useful libraries of react


Articles categorized as "Meteor by this user"
All articles of this user
Subscribe to RSS
RSS
Term
Category
All
1.Japan
2.Atlassian's products
3.Self
4.Development of this site
5.Japanese comics
6.Japanese anime
7.Weekly hot news of Japanese culture
8.OP/ED/PV
9.Japanese game
10.Ranking
11.Japanese Comics (Manga)
12.Search Engine
13.Japanese drama
14.Japanese otaku culture
15.Programming
16.Ineternet world
17.Movie
18.C/C++
19.BerkeleyDB
20.Apache programming
21.Spam
22.Meteor
23.Marketing
24.Python
25.Scrum
26.JIRA
27.Git
28.CI
29.Jenkins
30.AWS
31.Operation
32.Singapore
33.Cloud
34.Mysql Cluster
35.DevOps
36.Bitbucket
37.Xamarin
38.Good and new
39.Monitoring
40.JavaScript(node.js)
41.React
42.Phillipines
43.Hiring
44.Python
45.SEO
46.Malaysia
47.Mongodb
48.Perl
49.Docker
50.Life hack
51.Dance
52.QA
53.Mysql
54.Digital Life Hack
55.Project management
56.Django
57.Gatsby
58.Administrator
Sayings from S-Cry-Ed

Rule in this world is speed. Even stupid person can write cool novel if he can spend 20 years for it.

If someone helped me, I will help him in return, which is my rule.

To become stronger, consider what is cowardliest thinking. And rebel against the thinking, which will make you stronger.



I am Japanese but working for some English sites.

Doctor Job Career
Nurse Job Career
Top Page top MetaSeachJP Works