简体   繁体   中英

Meteor.js deploy to "example.com" or "www.example.com"?

I recently deployed a meteor app using the following command:

$ meteor deploy example.com

and later (thinking that it was the same) using the following:

$ meteor deploy www.example.com

It end up serving two different versions of the app, one hosted in example.com and other hosted in www.example.com .

Can I revert one of the deploys? Which one should I revert?

If not, what kind of configs should I set on my domain provider?

When people go to your page, do you want them to see mydomain.example or www.mydomain.example ?

If it's mydomain.example , then you want to set your DNS zone file with an A record for the domain that points to the IP of origin.meteor.com

If it's www.mydomain.example , then you want to set your DNS zone file with a CNAME for the subdomain "www" that points to origin.meteor.com

Then, you want to set "domain forwarding" from one of those choices to the other. For example, I've set up http://playlistparty.net to forward to http://www.playlistparty.net .

After this, you just run:

meteor deploy www.playlistparty.net

You can delete the deployment you won't be using with the --delete option.
 meteor deploy www.playlistparty.net --delete

Deploying on a custom domain name

Deploy meteor to your domain name:

meteor deploy mydomain.com

Set your CNAME record for *.mydomain.com or www.mydomain.com (if you only want to set the www subdomain) and mydomain.com to : origin.meteor.com

OR

point your 'A' record for *.mydomain.com and mydomain.com to : 107.22.210.133 .

To remove an exising one you might have typed by accident:

meteor deploy www.mydomain.com --delete

If you want www to redirect to non-www you can use this method. You can also modify the code a little to do it other way around.

Simply set

@ (CNAME) : origin.meteor.comm
www (CNAME) : origin.meteor.com

Then, deploy your main app (without www).

meteor deploy yourapp.example

Now, create a new meteor app called redirect with

meteor create redirect
cd redirect

Set the generated js file contents like this:

if (Meteor.isClient) {
  var url = document.URL;
  url = url.replace("www.", "");
  window.location.href = url;
}

Then deploy your redirect app (with www)

meteor deploy www.yourapp.example

What you did is, you deployed two different applications to www and non-www of your domain. All the meteor app at www does is to redirect you to non-www domain. It will also redirect www.yourapp.example/some/path to yourapp.example/some/path .

I did a lot of googling on this, so I'll share what ended up working for me. I was looking for all queries to go to the HTTPS and www version of my site. Just setting up the CNAME did not actually change to redirect to the www version. I'm hosting on Modulus and ended up doing the following:

  1. Force HTTPS

    • Modulus has an HTTPS redirect, else I've used the Force-SSL package and NGINX to do this successfully in previous apps not hosted on Modulus.
  2. Point domain at hosting IP

    • Set up you domain, example.com, A-record to point at our hosting IP.
    • Set up my CNAME for 'www' subdomain to point to the same IP.
  3. Force www

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM