Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple Meteor sites behind Nginx

Tags:

nginx

meteor

This question is related to this SO question, but the recommended solution in the comments to use Meteor.absoluteUrl() doesn't seem to be working as expected. I want to be able to deploy multiple meteor applications to the same server and use nginx as a reverse proxy to each application.

Because each application is segregated none of the applications are going to be accessible from the ROOT_URL, but Meteor is only using the ROOT_URL to reference back for the assets it needs to load a meteor app.

I tried appending to the address using Meteor.absoluteUrl() in the server's startup, the client's startup function, and outside of the client's startup function. It had no affect in any of these places.

For example. I have nginx listening at /site1 for server_name: example.com and a reverse proxy to port 3001 to my meteor application.

When going to the site it initially loads fine but the browser dev tool shows Meteor is trying to find the javascript and css files at https://example.com when it should be looking from a base url of https://example.com/site1

Meteor.absoluteUrl("site1",{ssl:true}) was set in Meteor.startup() to try and force that as the correct path. As you can see, I am only appending to ROOT_URL with no leading / as described in the Meteor documentation.

I'm using meteor up to deploy and here's how the mup.json environment settings look:

"env": { "ROOT_URL": "https://example.com", "PORT": 3001, "MONGO_URL": "mongodb://user:password@localhost:27017/db" }

Any clarification about this this should work is greatly appreciated.

like image 590
Fratt Avatar asked Nov 09 '22 06:11

Fratt


1 Answers

Using sub-domains suggested by apendua seems to be the easiest way to accommodate multiple Meteor applications on the same server behind nginx (if you that option available to you).

  1. Register a sub-domain for each application (i.e. app1.domain.com, app2.domain.com, etc.)
  2. Add an nginx server configuration for each sub-domain, setting the server_name property to your sub-domain address.
  3. Add a default location for that server and set your proxy_pass to http://127.0.0.1:port where port is the port number you set in your environment configuration when you deployed your Meteor application (in my case I set this in my mup.json).
like image 179
Fratt Avatar answered Nov 29 '22 12:11

Fratt