node.jsnginxmeteordeploymentmeteor-up

How can I deploy my meteor app to an Ubuntu server in my local network?


I have a simple meteor app, I want it to run on a local machine running Ubuntu in my local network with nginx so that it can be reachable from the browser with the machine's local IP address. I have tried using mup (meteor up) but it requires SSH keys and I have to use nginx so I have to deploy manually.

I would be appreciated if you can help me deploying the app, I can use and try different methods as long as it is running with nginx.

I don't need SSL at this point so I am trying to skip that step. Also, my MongoDB server is going to run on the same machine so I am trying to reach that locally too. I have tried this tutorial that is using forever to run meteor link but I couldn't figure to run it, also it does not explains how to configure my MongoDB URL and stuff.

I have Installed node, forever & meteor, created a new user, cloned my repository to my home server and I can run it with "meteor run" command locally.

I think I have problems with configuring nginx and the script that bundles the application that is explained in the tutorial I mentioned. I am not sure where to locate the env_settings.sh file. It is on my /etc/nginx/ directory.

here is my nginx config file

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

env_settings.sh

#load environment variables
source ../env_settings.sh

meteor update --release 1.11 #ensure proper version of Meteor

npm install # install NPM dependencies
npm prune --production # remove development dependencies

rm -rf ~/bundle # remove the previous bundle

meteor build --directory ~ # build the current bundle

cd ~/bundle/programs/server # enter the bundle
npm install # install dependencies

mv ~/bundle ~/portal 

# make sure the logs directory exists
mkdir ~/logs 

# use forever to restart the Node.js server
export PORT=8080
cd ~/portal
forever stop main.js
forever start -a -l ~/logs/forever.log -o ~/logs/portal.out -e ~/logs/portal.err main.js

sites_available/app

# this section is needed to proxy web-socket connections
map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
}
# HTTP
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
        
        location = /favicon.ico {
          root /home/webapp/portal/programs/web.browser/app;
          access_log off;
        }
        
        location ~* "^/[a-z0-9]{40}\.(css|js)$" {
          gzip_static on;
          root /home/webapp/portal/programs/web.browser;
          access_log off;
        }
        
        location ~ "^/packages" {
          root /home/webapp/portal/programs/web.browser;
          access_log off;
        }

        # pass requests to Meteor
        location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade; #for websockets
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
        }
}

Solution

  • I have handled this situation with the information in this link. It is not running the bundled version of meteor, but this is actually comes up as a better way to do it to make it easier to test on the local network.