Meteor.js deploy to “example.com” or “www.example.com”?

前端 未结 4 1830
鱼传尺愫
鱼传尺愫 2020-12-04 07:18

I recently deployed a meteor app using the following command:

$ meteor deploy example.com

and later (thinking that it was the same) using t

相关标签:
4条回答
  • 2020-12-04 07:30

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

    If it's mydomain.com, 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.com, 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
    
    0 讨论(0)
  • 2020-12-04 07:37

    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

      • Set the environment variable ROOT_URL to 'https://www.example.com'
      • Download the canonical package: https://atmospherejs.com/wizonesolutions/canonical
    0 讨论(0)
  • 2020-12-04 07:38

    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
    
    0 讨论(0)
  • 2020-12-04 07:47

    Okay guys, I found a simple way :

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

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

    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.com/some/path to yourapp.com/some/path. Simple yet powerfull solution :)

    0 讨论(0)
提交回复
热议问题