Suppose I have a Google App Engine application which has several modules which have several versions. Can I map a custom domain name to a specific version of a specific module of the application?
For example:
http://www.example.com should be mapped to http://module1-dot-app1.appspot.com
1.Mapping a module to custom domain
Let's suppose you are admin for domain example.com and you want to map subdomain www.example.com to module webmodule in your application myapp.appspot.com
www.example.com -> webmodule.myapp.appspot.com
What you can do is going to admin.google.com and in App Engine Apps section configure your application so that it is mapped on web address www.example.com. Of course follow the instruction for configuring your domain (you should add a CNAME entry in your DNS configuration with ALIAS www and HOST ghs.googlehosted.com).
Once you did this, web address www.example.com is linked to your application default module. For redirecting to webmodule you need to configure application internal routing with dispatch file, as reported here:
https://developers.google.com/appengine/docs/python/modules/routing
In your case what you need is something like this (this is from dispatch.yaml file for Python application):
dispatch:
- url: "www.example.com/*"
module: webmodule
2.Mapping a version to custom domain
Regarding versions, it seems you cannot map an url to a specific module version. What you can probably do is mapping an url including version to a specific module, but this is maybe little bit confusing.
As thetonrifles already pointed out, you must use the dispatch.yaml file, which goes in your default module.
However, I also came across some issues when using secure domains/subdomains. If you've already uploaded your SSL cert for your custom domain, and you add custom subdomains after the fact, you need to go back to the SSL cert section and enable those subdomains you added, otherwise they'll just keep showing blank.
Related
This page (https://cloud.google.com/appengine/docs/standard/nodejs/mapping-custom-domains) states:
Using subdomains
If you set up a wildcard subdomain mapping for your custom domain, then your application serves requests for any matching subdomain.
If the user browses a domain that matches an application version name or service name, the application serves that version.
If the user browses a domain that matches a service name, the application serves that service.
Also, this page (https://cloud.google.com/appengine/docs/standard/java/how-requests-are-routed) states:
Sends a request to an available instance of a specific version in the default service:
https://[VERSION_ID]-dot-[MY_PROJECT_ID].appspot.com
http://[VERSION_ID].[MY_CUSTOM_DOMAIN]
I have the following services for my App Engine project:
and following versions for this service:
"1" is the default version. "test1" is a test version.
Yet when I enter https://test1.mycustomdomain.com into a browser, it serves the default version, not the "test1" version.
If I enter https://test99.mycustomdomain.com into a browser, I see an error page because this version does not exist (as expected).
The URL, https://test1-dot-MY_PROJECT_ID.appspot.com/ works as expected (i.e. serves the "test1" version).
These are my configured domains:
How do I get App Engine to route a request to the correct version?
Any domain directly mapped to your app will serve the default service. If test1.mycustomdomain.com is mapped as a custom domain, it will always serve 1 (default).
To serve named GAE versions with a custom domain, you'll need to map the domain with the wildcard (*.mycustomdomain.com) and remove the other mapped subdomains that are conflicting with your versions. An example of working mapped domains would be:
mycustomdomain.com
www.mycustomdomain.com
*.mycustomdomain.com
With that setup, test1.mycustomdomain.com should serve the correct version, test1.
Edit
Regarding wildcard mapping and HTTPS
The GCP documentation about wildcard mapping states that:
Note: Wildcard mappings are not supported for managed SSL certificates.
This can lead to believe that wildcard mapping doesn't support HTTPS. The documentation is referring to the managed certificates that GAE provides. App Engine does support SSL certificates for wildcards if you use your own SSL certificates:
Some App Engine features use special subdomains. For example, an application can use subdomains to address application services, or to address different versions of your application. To use these with SSL, it makes sense to set up a SAN or wildcard certificate. Wildcard certificates only support one level of subdomain.
I set up a custom domain with App Engine after following the instructions on DNS records:
https://cloud.google.com/appengine/docs/standard/java/mapping-custom-domains
It's working for the default service using URL
http://MY_CUSTOM_DOMAIN but I'm unable to access other services with URLs http://SERVICE_ID.MY_CUSTOM_DOMAIN. Do I need to map a different set of DNS records?
Here's a step-by-step:
Ensure you are a owner of the parent domain in here: https://www.google.com/webmasters/verification/home (e.g for subdomain.example.com you need to own example.com)
If not, ask a friend to add you as an owner.
Create a CNAME record pointing to: ghs.googlehosted.com (in Cloud DNS or wherever).
Note: This will cause downtime, but it is required for App Engine to create an SSL certificate so downtime is unavoidable...
Add custom domain to App Engine
Go to App Engine -> Settings -> Custom Domains
Click on Add a custom domain
Choose the verified parent domain and click Continue
Enter the subdomain (e.g subdomain.example.com) and click Save mappings
Click Done (you already did this last step)
Update App Engine dispatch rules
Run gcloud app describe --project <GOOGLE_CLOUD_PROJECT_ID> and take a look at the current section of dispatchRules
Create dispatch.yaml or dispatch.yml file with your new rule as well as the ones already existing above (note the file format is different from the command output)
dispatch:
- url: <DOMAIN>/* # e.g. subdomain.example.com/*
service: <SERVICE-NAME>
Deploy it using: gcloud app deploy dispatch.yaml --project <GOOGLE_CLOUD_PROJECT_ID>
Check how to use subdomains and how wildcard mapping works in the GCP docs here (actually these are the next steps at the website which you've followed and linked). Make sure that your DNS provider permits wildcards in CNAME host entries, otherwise such mapping will not be possible.
This blog post shows a real-life example of matching subdomains to services with App Engine.
I have an App Engine App at http://1.lyfekit.appspot.com/ and I want to use the custom domain http:// www. lyfekit .com/
I verified the domain and added it to app engine app settings. I added the CNAME record www pointing to ghs.googlehosted .com
BUT, http:// www. lyfekit .com/ is going to https: //lyfekit .com/ and is giving me an SSL error. I do not need https. I simply want http.
The way I understand, if I am not using https, I do not need to configure a Google Apps Account for the domain.
HTTPS is a protocol. It's totally separate from a domain name.
Somewhere in your app.yaml or web.xml file you have specified that you want a connection to be secure. App Engine follows your instructions and tries to use HTTPS protocol instead of HTTP protocol. Remove these instructions, and App Engine will stop using HTTPS
I'm not sure what you have done but the default module for your app (the one which your domain is mapped to) can be seen here:
http://lyfekit.appspot.com
and as you can see it redirects to https (because it will have secured:always set in the app.yaml file).
With your original URL you are specifying a particular version of your app (version 1) but as you can see by accessing the main appspot domain that version is not set as the default version.
I would like to know how I can point one of my module in appengine to a subdomain. For example:
module-one.myapp.appspot.com -> mydomain.com
module-two.myapp.appspot.com -> two.mydomain.com
Solution:
How #svpino say you have to set a wildcard.
Then you have to have something like this on your dispatch.yaml:
url: "two.mydomain.com/*"
And finally you have to create a custom domain name in the settings of App Engine.
You have to set up a wildcard subdomain: For example: *.app.example.com. You can read more about how to do this in the following link:
https://developers.google.com/appengine/docs/domain#more_about_wildcard_subdomain_mapping
If you set up a wildcard subdomain mapping for your custom domain,
then your application serves requests for any subdomain that matches.
If the user browses a domain that matches an application version name
or backend name, the application serves that version. If the user
browses a domain that matches a backend name, the application serves
that backend. For example, suppose you set up a wildcard subdomain
*.wild.example.com. Your application has two versions, the default version and one named beta. Your application has a backend server
named be with just one backend instance running.
You can use a CDN like cloudflare for that. You define a DNS rules like you want. If you don't need HTTPS you can define 3 DNS rules for free. If you need HTTPS the cost is 20$ per month and you can define more DNS rules. Using a CDN reduce the usage cost for your application and add many improvement.
Let's say I have myapp.appspot.com and two custom domains respectively called foo.com and bar.com. How do I configure Google App Engine (GAE) such that:
(www.)foo.com -> foo.myapp.appspot.com
(www.)bar.com -> bar.myapp.appspot.com
(www.)foo.com -> myapp.appspot.com (default version)
I'm reading https://developers.google.com/appengine/docs/domain but I still don't understand how to configure it. I get the impression that GAE only supports wildcard for one custom domain e.g. **.foo.com.
You can't really do that directly, as you associate your custom domain with an App ID rather than the App URL.
I guess you could map both foo.com and bar.com to your App ID, then in the default version of your App Engine parse the URL, and redirect accordingly, but it's not a great solution as you would be redirecting from your custom domain back to appspot.com domain.
You can route using the dispatch file (dispatch.yaml).
This blog post gave me the necessary info, and I imagine for the case of needing to map multiple domains to different modules would require a dispatch.yaml something like this:
# Dispatch
# ========
---
dispatch:
- url: 'foo.com/*'
module: foo
- url: 'bar.com/*'
module: bar
Don't forget to add the custom domains as well as SSL certs in the App Engine console.