Search code examples
meteormeteor-up

How to deploy meteor app in production server using Centos7


How to deploy the meteor in centos7.We installed the meteor and meteorjs packages and nodejs. But we unable to open the production link.Please help me.


Solution

    • First of all, you don't need to install meteor on production server. Node.js is enough.
    • On my Centos server, I use nginx + supervisord to run my meteor app.
    • You should build your app with "meteor build --directory " command. With this command you will get a bundle directory. Compress that bundle folder and upload it to the server. Example

      meteor build --directory <some_path>
      
    • Extract in on the server, then

      cd bundle/programs/server
      npm install
      
    • Example meteor app config in supervisord.conf file. All the meteor app specific config is in the 'environment' variable on this configuration. There will be other entries in your supervisord.conf file. You will have to add this one for your meteor app. For more info on supervisord, visit http://supervisord.org

      [program:my-meteor-app]
      command=node main.js              ; the program (relative uses PATH, can take args)
      directory=/home/path_where_bundle_is/bundle
      process_name=%(program_name)s ; process_name expr (default %(program_name)s)
      numprocs=1                    ; number of processes copies to start (def 1)
      autostart=true                ; start at supervisord start (default: true)
      autorestart=unexpected        ; whether/when to restart (default: unexpected)
      user=app_user                   ; setuid to this UNIX account to run the program
      redirect_stderr=true          ; redirect proc stderr to stdout (default false)
      stdout_logfile=/var/log/meteor.log        ; stdout log path, NONE for none; default AUTO
      stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
      stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)
      ;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
      ;stdout_events_enabled=false   ; emit events on stdout writes (default false)
      stderr_logfile=/var/log/meteor_err.log        ; stderr log path, NONE for none; default AUTO
      stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
      stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)
      ;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)
      ;stderr_events_enabled=false   ; emit events on stderr writes (default false)
      environment=PORT="3003", ROOT_URL="https://your_url",MAIL_URL="smtp://xxx:xxx@smtp.mailgun.org:25",MONGO_URL="mongodb://xxx:xxx@localhost/databasename"       ; process environment additions (def no adds)
      ;serverurl=AUTO                ; override serverurl computation (childutils) 
      
    • For nginx configuration, this is my configuration concerning meteor app (this is not the whole config file just the part necessary for meteor):

          location / {
         proxy_pass http://localhost:3003/;
         proxy_set_header Host $host;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "upgrade";
         proxy_http_version 1.1;
      }
      

    For more detailed information on setting up nginx, you can check out digitalocean documentation: https://www.digitalocean.com/community/tutorials/how-to-deploy-a-meteor-js-application-on-ubuntu-14-04-with-nginx

    When everything is ok:

        supervisorctl start all
        service nginx start
    
    • I am running meteor app on port 3003 and redirecting requests to that port using nginx. You might want to add an iptables rule to drop connections to port 3003, so that only nginx can connect to port 3003. Here are two iptables rules to deny mongodb and port 3003 connections from public networks.

      iptables -A INPUT -i eth0 -p tcp -m tcp --dport 27017 -j DROP
      iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3003 -j DROP