By default, Serverless App Engine (SAE) applications cannot access the public network, and the public network cannot access the private network. To solve this problem, you can configure Application Load Balancer (ALB) gateway routing for your applications to enable normal access to SAE applications from the public network. This topic explains the important parameter configurations for ALB gateway routing.
Overview of forwarding rules
You can add multiple forwarding rules to a listener of an ALB instance from the SAE side. For a forwarding rule, from the perspective of data link direction, there are inbound forwarding rules and outbound forwarding rules. On the SAE side, you can only configure inbound forwarding rules for ALB instances. If you need to configure outbound forwarding rules, you need to do so on the SLB side.
A forwarding rule consists of two parts: forwarding conditions and forwarding actions. When a request matches the conditions specified in a forwarding rule, the actions specified in the forwarding rule are performed. You can specify one or more conditions and one or more actions in a forwarding rule.
For ALB instances of Standard Edition and WAF-Enabled Edition, when a client sends a request to the ALB, the ALB processes the request data through inbound forwarding rules and then sends it to the corresponding backend server. The response data from the backend server is processed through the ALB's outbound forwarding rules before being returned to the client.
When you create an inbound forwarding rule, you can specify only inbound conditions and actions.
When you create an outbound forwarding rule, you can specify both inbound and outbound conditions. However, you can specify only outbound actions in an outbound forwarding rule.
A forwarding rule must include one forwarding action of the type forward to, redirect to, or return fixed response to ensure that client requests are not interrupted.
Access path
Log on to the SAE console, click Namespaces in the left-side navigation pane, and then select the target region.
On the Namespace page, click the name of the target namespace.
On the Basic Information page of the target namespace, click Gateway Routing in the left-side navigation pane, and then click Create Gateway Route.
This topic only introduces the configuration of key parameters. For detailed instructions on creating gateway routing, see Configuring Route Rules by Application Load Balancer (ALB).
Forwarding conditions configuration
On the SAE side, you can configure forwarding conditions for Domain Name, Access Port, and Path.
Domain name configuration
Configuration rule | Description |
Exact match and wildcard match |
|
Regular expression match |
|
Path configuration
Configuration rule | Description |
Exact match and wildcard match |
|
Regular expression match |
|
Introduction to forwarding action configuration
In the forwarding action configuration, you can configure rewrite policies and redirection rules.
Rewrite policy configuration
You can configure rewrite policies in forwarding actions.
When you select "Forward to", you can configure rewrite policies.
For domain name configuration in forwarding conditions, see Domain name configuration.
If the redirected domain name is the default
${host}, it means dynamically replacing it with the original request's domain name.
Path configuration
After configuring a regular expression for the path in forwarding conditions, the path in forwarding actions supports regular expression replacement. For information about how to add forwarding rules, see Configure routing rules for an application (ALB).
Notes
The number of parentheses
()in the regular expression in the forwarding condition must match the number of$variablesin the rewritten path in the forwarding action.The rewritten path in the forwarding action must include one or more of
${1},${2}, and${3}, and these three variables cannot be replaced with other characters.
Replacement principle
URL matching: The client sends a request and the request matches a regular expression that is specified in a forwarding rule.
Extraction and replacement: According to regular expression standards, the content extracted from the first three pairs of parentheses
()is saved to${1},${2}, and${3}respectively, for replacement in the rewritten path of the forwarding action.Concatenation: According to the configuration of the rewritten path in the forwarding action, replace the values of
${1},${2}, and${3}, and finally concatenate them into the actual rewritten path.
Number
Step
Example
1
Configure the forwarding condition and the forwarding action in a forwarding rule.
Forwarding condition path:
/sys/(.*)/(.*)/aaaForwarding action rewrite path:
/${1}/${2}
2
A client request matches the path in a forwarding rule.
Client request path:
/sys/ccc/bbb/aaaMatched forwarding condition path:
/sys/(.*)/(.*)/aaa
3
Extraction and replacement.
According to regular expression standards, the two
(.*)in the forwarding condition path extractcccandbbbrespectively, and store them in${1}and${2}in the rewritten path of the forwarding action.${1}is replaced withccc${2}is replaced withbbb
4
Path concatenation.
Path received by the backend server:
/ccc/bbb
If the redirected path is the default ${port}, it means dynamically replacing it with the original request path. For example, if the path in the forwarding condition is /test/aaa, then the path matched by the forwarding action is /test/aaa.
Query configuration
The query content refers to the part after the question mark in the URL. If the redirected query is the default ${query}, it means dynamically replacing it with the original request's query parameters.
Example:
If the client accesses the URL www.example.com/test/test1?x=1, the query content is x=1.
Redirection policy configuration
If you need to configure a redirection policy, you need to configure parameters such as protocol, domain name, access port, path, query, and status code.
Protocol introduction
An HTTP listener supports redirecting HTTP requests to another HTTP listener or an HTTPS listener.
An HTTPS listener supports redirecting HTTPS requests to another HTTPS listener.
If the redirected protocol is the default $(protocol), it means dynamically replacing it with the original request's protocol.
Domain name introduction
The domain name configuration in forwarding actions is the same as in forwarding conditions. For specific configuration, see Domain name configuration.
If the redirected domain name is the default ${host}, it means dynamically replacing it with the original request's domain name.
Access port introduction
Configure the listening port for the corresponding protocol. For example, when an HTTP request (access port: 80) is redirected to HTTPS (access port: 443).
If the redirected access port is the default ${port}, it means dynamically replacing it with the original request's port.
Path introduction
After configuring a regular expression for the path in forwarding conditions, the path in forwarding actions supports regular expression replacement. For information about how to add forwarding rules, see Configure routing rules for an application (ALB).
Notes
The number of parentheses
()in the regular expression in the forwarding condition must match the number of$variablesin the redirected path in the forwarding action.The redirected path in the forwarding action must include one or more of
${1},${2}, and${3}, and these three variables cannot be replaced with other characters.
Replacement principle
URL matching: The client sends a request and the request matches a regular expression that is specified in a forwarding rule.
Extraction and replacement: According to regular expression standards, the content extracted from the first three pairs of parentheses
()is saved to${1},${2}, and${3}respectively, for replacement in the redirected path of the forwarding action.Concatenation: According to the configuration of the redirected path in the forwarding action, replace the values of
${1},${2}, and${3}, and finally concatenate them into the actual rewritten path.
Number
Step
Example
1
Configure the forwarding condition and the forwarding action in a forwarding rule.
Forwarding condition path:
/sys/(.*)/(.*)/aaaForwarding action redirect path:
/${1}/${2}
2
A client request matches the path in a forwarding rule.
Client request path:
/sys/ccc/bbb/aaaMatched forwarding condition path:
/sys/(.*)/(.*)/aaa
3
Extraction and replacement.
According to regular expression standards, the two
(.*)in the forwarding condition path extractcccandbbbrespectively, and store them in${1}and${2}in the redirected path of the forwarding action.${1}is replaced withccc${2}is replaced withbbb
4
Path concatenation.
Path received by the backend server:
/ccc/bbb
If the redirected path is the default ${port}, it means dynamically replacing it with the original request path. For example, if the path in the forwarding condition is /test/aaa, then the path matched by the forwarding action is /test/aaa.
Query introduction
The query content refers to the part after the question mark in the URL. If the redirected query is the default ${query}, it means dynamically replacing it with the original request's query parameters.
Example:
If the client accesses the URL www.example.com/test/test1?x=1, the query content is x=1.
Status code introduction
The default HTTP status code for ALB redirects is 301. You can specify an HTTP status code as needed. The following table describes the HTTP status codes supported by ALB:
Status code | Description |
301 | Indicates permanent redirect. |
302 | Indicates temporary redirect. |
303 | Indicates that the requested resource can be obtained through another URL (see other location). |
307 | Indicates that the requested resource has temporarily moved to another location (temporary redirect, method preserved). |
308 | Indicates that the requested resource has permanently moved to a new location (permanent redirect, method preserved). |