Meteor - What is the purpose of “ROOT_URL” and to

2020-05-26 15:03发布

问题:

I'm getting some problems to make spiderable work with PhantomJS on my Ubuntu server. I saw this troubleshooting on Meteorpedia:

Ensure that the ROOT_URL that your Meteor server is configured to use is accessible from the server itself. (Since v0.8.1.3[1])

I think that this could be a possible answer to why it is not working. What is exactly the purpose of this environment variable?

My application is publicly accessible on http://gentlenode.com/ but my proxy_pass on nginx is set to http://gentlenode/.

# HTTPS Server
server {
    listen 443;
    server_name gentlenode.com;
    # ...

    location / {
        proxy_pass http://gentlenode/;
        proxy_http_version 1.1;
        # ...
    }
}

Should I set ROOT_URL to http://gentlenode.com/, to http://gentlenode/ or to http://localhost/?

You can find my nginx configuration here: https://gist.github.com/LeCoupa/9877434

回答1:

The ROOT_URL environment variable should be set to the URL that clients will be accessing your application with. So in your case, it would be http://gentlenode.com or https://gentlenode.com.

The ROOT_URL environment variable is read by Meteor.absoluteUrl, which is used in many (core) packages. Thus, setting ROOT_URL may be a requirement if you use these packages. spiderable is one such package.

// Line 62 of spiderable_server.js
var url = Spiderable._urlForPhantom(Meteor.absoluteUrl(), req.url);


回答2:

I'll admit that we don't use spiderable so I'm not 100% certain if this will fix your problem, but here's what we do...

We set ROOT_URL to the URL which clients will use to initially connect. In your case, the nginx config automatically upgrades all HTTP requests to HTTPS, so all requests will be seen by your app under https://gentlenode.com. I think you should start your server after:

export ROOT_URL=https://gentlenode.com

Your proxy_pass section may be correct. We manually spell out the name of the local port. So we'd write:

proxy_pass http://localhost:58080;

If you have something that works already, this may not be necessary. I don't know all the quirks of nginx well enough to say if that part matters.



标签: nginx meteor