Multiple Meteor sites behind Nginx

泄露秘密 提交于 2020-01-02 05:14:28

问题


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.


回答1:


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).



回答2:


The root url for public assets under a meteor app is actually at /public. Each of your apps has a different base directory for the app. Assuming that you have an overall structure that looks like:

app1/ - nginx maps to https://example1.com/
  client/
  lib/
  public/
  server/
app2/ - nginx maps to https://example2.com/
  client/
  lib/
  public/
  server/
etc...

Then each app's public assets will just be under Meteor.absoluteUrl() which will serve files from app/public. Meteor.absoluteUrl()+"app1" has no meaning.



来源:https://stackoverflow.com/questions/32170123/multiple-meteor-sites-behind-nginx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!