How to use unverified custom domains with Google A

2019-06-11 07:10发布

问题:

I need customers to be able to point their own custom domains to my GAE app.

e.g. customersdomain.com -- CNAME --> myapp.com (which in turn points to myapp.appspot.com)

I know that I can link a domain to my Google account and then use that domain to serve app engine, but this process does not scale and requires that I have direct access to the customer's domain register/DNS. The only other alternative is to force customers to sign up for Google Apps (why!).

Almost all other PaaS make this process painless:

  • In Heroku, I simply add the domain to a whitelist and the customer adds a CNAME record.
  • In AWS, a single CNAME record pointing to the instance does the trick.

Does anyone know of a workaround for this? Or am I just going to have to manually link hundreds of domains to my account?

回答1:

You are asking for something impossible. App Engine does not use fixed IPs, so it cannot decide what application it should serve based on IP. The choice is made by the request that contains the URL, like so:

GET http://custom.example.com/resource.html

A server extracts the domain part "custom.example.com" and decides upon this domain which application is meant by your request. In order to do so it must have a mapping table with what domain maps to what application. It is this mapping table that you must fill by entering your domains in the developers console.

When you have cname records on your domain the browser first resolves an IP for your request. The same IP addresses are shared between all app engine applications, so the IP address alone is useless to determine your application. So no, you cannot just add CNAMEs and expect appengine to just know what to do, you'll have to tell appengine that explicitly.

Speaking of explicit. You can use wildcards for custom domains. Maybe that can help. Otherwise the only option i see for customers to create their own forwards is to use frames. Many domain providers offer a service that will host a very simple html page that will show the target website in a full width/height frame. I always feel like the frame solution is some sort of cheat but it might be the best choice in your case.