I plan to make a main website and a blog.
www.domain-name.com will be my main website and blog.domain-name.com
will be my blog.
I am able to achieve this on my appspot domain, but on my custom domain, it doesn't work.
https://blog-dot-domainname.appspot.com/ is showing the correct
webpage.
Currently blog.domain-name.com shows the exact same thing as www.domain-name.com.
Here's what I did:
dispatch.yaml file
dispatch:
# Default module serves the typical web resources and all static resources.
- url: "*/favicon.ico"
module: default
- url: "domain-name.com"
module: default
- url: "blog.domain-name.com/*"
module: blog
I also setup two custom domain names on the AppEngine settings:
CUSTOM DOMAIN NAMES domain-name.com blog.domain-name.com
I am using Namecheap and I setup the required CNAME alias for my bog subdomain.
Related
I have two subdomains registered in my App Engine application:
service-a.my-app.com
service-b.my-app.com
I have added all the records (CNAME, A) on the server.
I have three services in my GAE:
default
service-a
service-b
And I want each subdomain to point to the correct service. However, each time I access them, only the default service is used.
Side note: the GAE is running a flexible environment for laravel 5.4 and my dispatch.yaml (located in default service is as follows:
dispatch:
-url: "service-a.my-app.com/*"
service: service-a
-url: "service-b.my-app.com/*"
service: service-b
This worked for me. Hope this helps someone.
GAE Standard:
I have an angular project which will load for any subdomain except one subdomain "api".
The backend is written in Go and all services are under a service named "api"
STEP1: Setting local env
Angular project has the following app.yaml
runtime: python27
api_version: 1
instance_class: F1
handlers:
- url: /
static_files: default/index.html
upload: default/index.html
- url: /
static_dir: default
My service.yaml file resides in a separate directory and has the following
runtime: go
api_version: go1
instance_class: F1
service: api
handlers:
- url: /.*
script: _go_app
secure: always
My dispatch.yaml has the following
dispatch:
- url: "api.MYDOMAINNAME.com/*"
service: api
//Add more subdomain : services mapping here
I deployed all these files using gcloud app deploy command
Step 2 - Configure Custom domains in GAE.
In GAE Console, goto Project Settings > Custom Domains
Add your domain
Verify your domainusing one of the methods provided by Google.
Update CNAME, A and AAA records in your domain service provider's DNS Settings
Step 3 - Configure Sub Domain
Add a subdomain api.MYDOMAINNAME.com
Add the CNAME in your domain service provider's settings.
// add more subdomains if required
Add a Wildcard subdomain *.MYDOMAINNAME.com
Add the CNAME in your domain service provider's settings to redirect * to google.
Finally:
Wait for few minutes for the settings to be applied.
Now your application will redirect MYDOMAINNAME.com, www.MYDOMAINNAME.com , *.MYDOMAINNAME.com to the Angular code
and
api.MYDOMAINNAME.com to your api service
Please note that dispatch.yaml is an app-level configuration, not a service-level one and occasionally updating the service containing it doesn't automatically update the app-level configs.
You should use the specific deployment commands for dispatch.yaml, executed from the directory containing the file:
gcloud app deploy dispatch.yaml if you're using the Cloud SDK
appcfg.py update_dispatch . if you're still using the GAE SDK
See also dispatch.yaml not getting updated.
The same is true for other app-level .yaml config files as well, which is probably one reason for each having its own update/deploy command (and also to allow deploying them independently of any particular app service. Somehow related: Why do I need to deploy a "default" app before I can deploy multiple services in GCP?
Actually the answer was really easy: You just need to map a wildcard subdomain and GAE would the use the service corresponding to the prefix.
I have a Google App Engine project with following yaml file
handlers:
- url: /web/.*
script: web_server.app
- url: /api/.*
script: rest_server.app
How do I make sure subdomain, of a domain I own, be served by rest_server.app script.
Example: If I own example.com
I want example.com to be served by web_server.app, and api.example.com to be served by rest_server.app
Is it possible to do that using Google App Engine.
Example:
handlers:
- url: example.com/.*
script: web_server.app
- url: api.example.com/.*
script: rest_server.app
Request routing in the app.yaml can not be used to route based on the URL's domain name, see the url table row in the Handlers element doc section.
Because of that you can't really have a single module/service serving your app while simultaneously stripping the filepath portion of the URL you're currently used in your handlers' url configs for routing requests to one script or the other.
You can obtain what you desire by splitting your app into 2 separate services/modules, each handling one script. One of the modules has to be the default module, I'd make the web one the default.
A dispatch.yaml file would be used to route requests to their respective modules based on the URL hostname.
The web.yaml file would contain:
module: default
handlers:
- url: /.*
script: web_server.app
The rest.yaml file would contain:
module: rest
handlers:
- url: /.*
script: rest_server.app
In the dispatch.yaml file you only need routes for the non-default module(s), requests matching no routes are by default routed to the defaut module:
- url: "api.example.com/*"
module: rest
You can find a more complete example here: https://stackoverflow.com/a/34111170/4495081
You'd then map both your example.com naked domain and api.example.com subdomain to your app. Follow the Adding a custom domain for your application procedure, paying extra attention to the sections which are slightly different when configuring a naked domain vs a subdomain. See also https://stackoverflow.com/a/36317462/4495081
There is one problem, tho - dispatch.yaml routing based on hostnames doesn't work with the local development server, the requests destined for the rest module would actually go to the default module.
A simpler workaround would be to direct the rest module clients to the actual localhost:PORT URL where the local devserver's rest module listens (displayed in the terminal at dev server startup), instead.
This might not be possible in all cases or for all apps. For example it's an issue if the app makes cross-module requests with auto-generated URLs.
In such cases, to work around it you can temporarily insert a small path portion in the rest.yaml URL, only during testing on the local dev server the rest module (you'd need matching changes on the client side and/or the cross-module URL generation logic):
module: rest
handlers:
- url: /api/.*
script: rest_server.app
And then you can add a dispatch.yaml rule that is not host-based and would also with the local dev server. This can be left in there permanently, it doesn't hurt if/when deployed in production when the temporary rest.yaml change is reversed:
- url: "api.example.com/*"
module: rest
- url: "*/api/*"
module: rest
This is a basic sense check question as i'm deploying a few new modules:
dispatch.yaml:
application: my-app
# No version required; this does routing independent of version.
dispatch:
# Default module serves the typical web resources and all static resources.
- url: "*/favicon.ico"
module: default
# Default module serves simple hostname request.
- url: "simple-sample.appspot.com/"
module: default
# Send all mobile traffic to the mobile frontend.
- url: "*/mobile/*"
module: mobile-frontend
# Send all work to the one static backend.
- url: "*/work/*"
module: static-backend
Wouldn't it be safer to put "*.com/mobile/*" instead of "*/mobile/*" ? In case other modules could use /mobile/ in their urls somewhere and accidentally get routed to mobile-frontend?
What if I have domain names other than .com e.g. .io?
Yes, it could be considered safer in the way you're looking at it.
For the additional .io (or other) domains you can add a rule for each of those suffixes:
- url: "*.com/mobile/*"
module: mobile-frontend
- url: "*.io/mobile/*"
module: mobile-frontend
Side note: you don't actually need to specify the rules for the default module - all requests not matching any rules in the dispatch files are by default routed to the default module, making such rules redundant. You can test this by making a request not matching any of your dispatch.yaml rules and watching the default module's logs.
I configured my dispatch.yaml file to route /admin to Admin module. But I want to route my sub-domain to route the Admin module.
My dispatch.yaml file contains the following code
- url: "*/admin"
module: admin
- url: "*/admin/*"
module: admin
In admin module
app = webapp2.WSGIApplication([
routes.DomainRoute('admin.knowyouroffers.in', [
webapp2.Route('/', handler=Admin, name='home'),
]),debug=settings.debug)
I tried the following code in dispatch.yaml. But It couldn't work
- url: "admin.knowyouroffers.in/*"
module: admin
You don't need to specify the domain in the admin module, that code gets invoked only after the request has been already routed to the module following the dispatch.yaml rules. Plain path routing in the module is enough and it also allows you to test your code before deploying in production (which otherwise is the only place where the domain would be filled in properly to match the routing rules).
Check your request logs in all modules to debug routing. See also this Q&A:
Appengine: Routing with dispatch.yaml
I've been having troubles trying to connect a module to my custom domain.
I works perfectly on the appspot domain but not on my custom domain.
E.G.
http://m.myappname.appspot.com calls the dispatch.yaml file which routes the request to my mobile frontend
BUT
http://m.myappcustomdomain.com serves the default module (app.yaml)
Any help will be highly appreciated.
Thanks
You could an entry like this in your dispatch.yaml file:
- url: "m.myappcustomdomain.com/*"
module: your_mobile_module