Media CDN provides advanced HTTP routing capabilities that allow you to map traffic to specific edge configurations and origins at a fine-grained level.
Configure a route rule
Configure a route rule for a Media CDN service.
Console
In the Google Cloud console, go to the Media CDN page.
To open the Details page of the service for which you want to configure a route rule, click the service name.
To switch to the edit mode, click the Edit button.
To navigate to the Routing section, click Next.
Specify at least one host rule. Click Add host rule. Then, do the following:
For Hosts, specify at least one host for matching.
For Description, provide a brief description for the host rule.
Alternatively, to edit a host rule, click the arrow to expand it.
Specify at least one route rule. Click Add route rule.
Alternatively, to edit a route rule, click Edit on the respective row.
In the Edit route rule pane, for Priority, set a value for route priority.
For Description, provide a brief description that can help identify the rule in a list of rules.
In the Match section, specify at least one match condition. Click Add a match condition. Then, do the following:
- For Match type, select any path match option.
For Path match, specify the names, paths, or templates. Consider using wildcard pattern matching.
If required, also select Enable case sensitivity for path value.
Optional: Select Headers match and Query parameters match. Then, click the relevant buttons to add headers and query parameters. For each, specify the name, match type, and value.
For more information, see Match on headers and query parameters.
To save the match condition, click Done.
For Primary action, select one of the following options:
Fetch from an origin: To direct requests to a specific origin, select this option, and then select an origin.
URL redirect: To redirect requests, select this option. Then, specify the type of redirect, the path, and the status code.
Optionally, select the options to redirect all responses to HTTPS, or to strip the query.
Click Advanced configurations.
In the Header action section, click Add an item.
Select a type of action and then specify a header as a name and value pair. Then, click Done.
In the Route action section, click Add an item.
Specify a type of action and its related options. Then, click Done.
For HTTP method filtering, select Customize HTTP method filtering.
Then, select the HTTP methods that you want proxied to your origin.
To save the route rule, click Save.
To save your changes to the service, click Update service.
gcloud and YAML
Export your Media CDN configuration into a YAML file. Use the
gcloud edge-cache services exportcommand.gcloud edge-cache services export SERVICE_NAME \ --destination=FILENAME.yamlReplace the following:
SERVICE_NAME: the name of your serviceFILENAME: the name of your YAML file
Update the YAML file with the required configuration as described in the sections on this page.
To update the service, import your Media CDN configuration from the YAML file. Use the
gcloud edge-cache services importcommand.gcloud edge-cache services import SERVICE_NAME \ --source=FILENAME.yaml
Match requests
A Media CDN configuration contains a set of routes defined in the
Routing
section for an
EdgeCacheService
resource.
These routes match requests based on (at least) a host. For more details about how
traffic is directed to an origin, see
HostRule
and PathMatcher.
Each route is able to define its own CDN configuration, rewrites, redirects,
CORS policies, custom HTTP headers, and origin mapping.
Routes can share origins.
For example, you can route requests for manifests to a specific origin and define a short-lived cache TTL and a negative caching policy. Requests for segments can be split to another origin by using headers and query parameters to break out specific manifest types or users.
The following example shows how to route requests that match a specific header,
query parameter, and path prefix for the host media.example.com:
name: prod-service routing: hostRules: - hosts: - media.example.com pathMatcher: example_routes pathMatchers: - name