{"id":148,"date":"2015-11-29T00:35:54","date_gmt":"2015-11-29T04:35:54","guid":{"rendered":"http:\/\/zhouanbo.com\/?p=148"},"modified":"2018-07-12T13:20:46","modified_gmt":"2018-07-12T17:20:46","slug":"multiple-meteor-instances-on-one-server-with-nginx","status":"publish","type":"post","link":"https:\/\/zhouanbo.com\/?p=148","title":{"rendered":"Multiple Meteor instances on one server with nginx"},"content":{"rendered":"<p>As a good full stack platform as it is, meteor doesn&#8217;t have explicitly documentation for customization of the environment underneath.<\/p>\n<p>I&#8217;m about to start coding a web application with an idea of starting with a core user API first, and slowly work on developing a series of extensions around the user API. This means I&#8217;ll have a single database queried and maintained by multiple meteor apps. In addition, all of the meteor apps will be set up in a single VPS to save money for my body&#8217;s digestive system.<\/p>\n<p>I disregarded the meteor self-contained databases and install a mongodb of my own.<\/p>\n<pre><code class=\"bash\">sudo apt-key adv --keyserver hkp:\/\/keyserver.ubuntu.com:80 --recv 7F0CEB10\necho \"deb http:\/\/repo.mongodb.org\/apt\/ubuntu trusty\/mongodb-org\/3.0 multiverse\" | sudo tee \/etc\/apt\/sources.list.d\/mongodb-org-3.0.list\nsudo apt-get update\nsudo apt-get install -y mongodb-org\n<\/code><\/pre>\n<p>In the shell:<\/p>\n<pre><code class=\"bash\">mongo\nuse [database]\ndb.createUser({ user: \"&lt;name&gt;\",\n  pwd: \"&lt;cleartext password&gt;\",\n  roles: [\n    { role: \"&lt;role&gt;\", db: \"&lt;database&gt;\" } | \"&lt;role&gt;\",\n    ...\n  ]\n})\n<\/code><\/pre>\n<p>to create a new database and a new user.<br \/>\nI use mup for deploying multiple Meteor app on the server. Mup is installed on the local machine through npm. In the same Meteor project folder on the local machine:<br \/>\n<code>mup init<\/code><br \/>\nthen add the environment variable in mup.json:<\/p>\n<pre><code>\"PORT\": 300X\n\"MONGO_URL\": \"mongodb:\/\/[username]:[password]@localhost:27017\/[database]\"\n<\/code><\/pre>\n<p>and change &#8220;setupMongo&#8221; to false.<br \/>\nThis way, meteor will run in separate ports connect to the database set by the environment instead of its own.<\/p>\n<p>After that, create A records for subdomains in the domain zone file, and point them all to the server&#8217;s IP address.<\/p>\n<p>Install nginx to take meteor&#8217;s place of dealing with http requests. In \/etc\/nginx\/site-avaliable\/, make new sites and put proxy_pass configurations in:<\/p>\n<pre><code>server {\n    listen  80;\n    server_name subdomain.doamin.com;\n    root  \/home\/user\/meteorapp;\n    location \/ {\n        proxy_pass http:\/\/domain.com:300X;\n    }\n}\n<\/code><\/pre>\n<p>Finally,<\/p>\n<pre><code>nginx -s reload\n<\/code><\/pre>\n<p>and starting all the Meteor instances to see multiple Meteors running in harmony.<\/p>\n<p>EDIT: specify &#8220;setupMongo: true&#8221; will automatically have multiple Meteor instances share the same mongodb.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a good full stack platform as it is, meteor doesn&#8217;t have explicitly documentation for customization of the environment underneath. I&#8217;m about to start coding a web application with an idea of starting with a core user API first, and &#8230; <a class=\"styledbutton\" href=\"https:\/\/zhouanbo.com\/?p=148\">Read More<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[6],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6eWPT-2o","_links":{"self":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/148"}],"collection":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=148"}],"version-history":[{"count":10,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions"}],"predecessor-version":[{"id":231,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=\/wp\/v2\/posts\/148\/revisions\/231"}],"wp:attachment":[{"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhouanbo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}