AppEngine Modules to subdomain - google-app-engine

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.

Related

Map custom sub-domain to specific version on App Engine

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.

Subdomain to resolve to a different website via DNS

I have two websites: (A) one is a static website hosted on github while the other (B) is an admin page hosted on Google Cloud (app engine). Currently, the DNS is set up so that the root of the site resolves to A. I would like to set up a sub-domain such as admin.root.com/ to resolve instead to B. I don't want to simply redirect the user as I would like the URL to be the one of the site.
Is there a way to achieve this via DNS? Note: I am using CloudFlare for the DNS settings.
Sure you can, all you need is just to set up a CNAME record for that on the DNS which manages root.com.
Supposing you want admin.root.com to point to somepage.github.com, the CNAME record shall consist of the following key/value pair:
key: admin
value: somepage.github.com.
If you want to redirect the user depending on the URL, you should configure and deploy the dispatch.yaml in your Google Cloud App Engine application. Find below the information depending on the environment that you are using:
AE Standard environment
AE Flexible environment
To use this solution, you should first resolve to B.

App Engine custom domain with service

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.

Google App Engine Wildcard Subdomains

I have Node JS app running on google app engine.
I have linked a custom domain to it: www.singlelisting.co
BUT
I need wildcard subdomains to also link to the node application
For Example: 6.singlelisting.co or ns324.singlelisting.co
I have not had much luck reading the documentation on google developers site
I am using cloudflare for DNS management and have added * records for all the google A and AAAA records. I believe the problem is have google is seeing the subdomains. Any help would be greatly appreciated
You have two options:
Mapping subdomains: in your App Engine Custom domains config you need to add the following entry *.singlelisting.co and then update the DSN management with the required records (as you probably did). This means that requests through 6.singlelisting.co or ns324.singlelisting.co will be handled by the 6, respectively ns324 service of you App Engine deployment, if available. As the documentation states:
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 a service name, the application serves that service.
By using a dispatch file (more info here): this file will override the routing rules established (or not) through your domains config.
So basically if you do not have services named 6 and ns324 that will automatically handle requests incoming through the wildcard rule *.singlelisting.co, you have to describe the routing using the dispatch.yaml.

Custom domain mapping to Google App Engine module or version

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.

Resources