If a vService listens on multiple ports, can I apply a different action or Backend Service per port (Destination Port)?
Short answer
Yes, on the HTTP and L7 TCP vService. The Destination Port condition compares the vService port the client connected to with an integer using the Less than, Equals to, Greater than or Range operator; in Range, both limits are included. If the condition is bound to a Conditional Backend Services block, the traffic coming to that port goes to different Backend Services; if it is bound to the Conditions field of an action, the action runs only on the traffic coming to that port. The condition is used in both the request and the response stage. If only a redirect from 80 to 443 is needed, no condition is required; Protocol = HTTP → HTTPS is selected in the Frontend row.
Problem: Ports Serve Different Services on a Single vService
Multiple ports, and also a port range in a single row, can be defined in the Frontend list of a vService. For example, if port 443 serves end users and port 8443 serves the management interface, the traffic coming to the two ports needs to go to different servers, or additional restrictions need to be applied to the management port. Without opening a separate vService, this distinction is made with a condition that looks at the port the request came to.
Solution: Two Methods
The two methods use the same Destination Port condition in different places, and they can also be applied together.
| Your situation | Suitable method |
|---|---|
| The traffic coming to each port must go to different Backend Services | Method 1: Conditional Backend Services |
| The Backend Service must stay the same; a different operation such as blocking or adding a header must be applied per port | Method 2: The Conditions field of the action |
| Only redirecting from HTTP to HTTPS | No condition is needed: Protocol = HTTP → HTTPS in the Frontend row |
Method 1: Conditional Backend Services Recommended
- How it works The Destination Port condition is bound to a Conditional Backend Services (Content Switching) block; requests coming to the port that fits the condition go to the Backend Services of the block, and the others go to Default Backend Services.
- Where it is openedLoad Balancer → Conditions → Destination Port · vService form → + Conditional backend services
- Requirement The ports being defined in the Frontend list of the vService; the target servers being defined as Backend Services
- vService type HTTP · L7 TCP
Step-by-Step Configuration
There must be a row for each port in the Frontend list of the vService. If one is missing, the vService is opened with Edit, a row is added with the (+) icon and Frontend IP is selected, a single port or a port range is written in the Port field, and the form is saved.
The condition form is opened with Load Balancer → Conditions → Add (how to add).
Condition Name is entered (e.g. port-yonetim) and Criteria = Destination Port is selected. The Destination Port field opens with Equals to selected and the value empty; the operator is selected and an integer is entered:
| Operator | Example | Matching port |
|---|---|---|
| Equals to | 8443 | Only 8443 |
| Less than | 1024 | Ports smaller than 1024 |
| Greater than | 8000 | Ports greater than 8000 |
| Range | 8000 - 8100 | Between 8000 and 8100, both limits included |
The Add button is clicked.
The Load Balancer → Load Balancer vService List steps are followed and the vService is opened with Edit.
The + Conditional backend services button in the Default Backend Services table is clicked.
The condition from step 3 is selected in the Select Conditions field of the block, and the Backend Services to which the traffic coming to this port will go are selected in the Backend Service selector.
The Save button is clicked.
Verification
On the HTTP vService, a record is clicked on the Logs & Tracking → HTTP Logs screen of the vService; the Connection Info row in the Summary tab of the preview shows the vService address and port the request came to, followed by the Backend Service that responded. For the record to be created, the LOG field must be on in the vService.
Request coming to :8443 → the Backend Service of the block · request coming to :443 → Default Backend ServicesThe same request is sent to the two ports separately.
curl -sk https://203.0.113.10:8443/ ; curl -sk https://203.0.113.10/The two responses come from different Backend ServicesMethod 2: The Conditions Field of the Action
- How it works The Destination Port condition is selected in the Conditions field of an action; the action runs only on the traffic coming to the port that fits the condition. The condition is listed in both On Request and On Response actions.
- Where it is openedLoad Balancer → Actions · vService form → Details → Actions
- Requirement The Destination Port condition created in steps 2–4 of Method 1
- vService type HTTP · L7 TCP (in the vService types that the action type supports)
Step-by-Step Configuration
The Load Balancer → Actions → Add steps are followed.
Action Name is entered and Action Type is selected; for example, Block for access to the management port only from specific addresses, and Add HTTP Header to inform the Backend Service which port the request came from. The Destination Port condition is selected in the Conditions field; if needed, it is combined with other conditions with and / or (e.g. Destination Port and the negated form of the Source IP condition).
The Add button is clicked.
The Load Balancer → Load Balancer vService List steps are followed, the vService is opened and the Details button at the top of the form is clicked.
The created action is selected in the Actions field.
The Save button is clicked.
Verification
In the Block action example, a request is sent to the two ports from an address that is not allowed.
curl -skI https://203.0.113.10:8443/ ; curl -skI https://203.0.113.10/8443: the block response selected in the action · 443: the response of the Backend ServiceCommon Mistakes
- Setting up a condition and an action for the 80 → 443 redirect. When Protocol = HTTP → HTTPS is selected in the Frontend row of the vService, requests coming to that port are redirected to HTTPS on their own; no separate condition is needed.
- Looking for "not equal" in the operator list. The list contains Less than, Equals to, Greater than and Range. If "if it is not this port" is needed, the negated form of the condition is selected in the condition selection lists (Can I use a condition in negated form ("if not")?).
- Thinking the Range limits are excluded. In Range, both limits are included in the range;
8000-8100covers both 8000 and 8100. - Confusing it with the port of the Backend Service. Destination Port is the vService port the client connected to; which port the request is forwarded to the Backend Service with is a setting of the Backend Service itself.
- Looking for the condition on the Network vService. The Destination Port condition is used only on the HTTP and L7 TCP vService.
How it is done in the documentation
Related questions
- Can I apply different rules per destination IP on a vService published on multiple IP addresses (Destination IP)?
- Can I use a condition in negated form ("if not")?
- What is the difference between Conditional Backend Services and Default Backend Services?
- What is the difference between a Condition and an Action?
