Can I return content directly for certain requests without going to the backend (Show Content)?
Short answer
Yes. When the Show Content action runs at the On Request stage, TR7 produces the response itself: the selected Content Page returns with the selected Status Code, and the request does not go to the Backend Service. By adding a condition to the Conditions field, it is applied only to specific paths or clients; if the condition is left empty, it is applied to all traffic. It is used for static responses such as robots.txt, a short JSON response or an access block page; it is available only on the HTTP vService. The Status code default is 200.
Problem: Going to the Server for a Simple Response Is Unnecessary
For content that does not change, such as robots.txt, a fixed JSON response, a temporary notice or an access block page, the request going to the Backend Service creates unnecessary load; for some paths, it is desired that the server is not reached at all.
Solution: Two Methods
Show content ends the request: the request actions that come after it in the Actions list do not run for that request, and no Backend Service is selected.
| Your situation | Suitable method |
|---|---|
| A fixed response to specific paths or to all traffic (interface) | Method 1: Show content |
| From the command line | Method 2: WEB-CLI |
Method 1: Show Content Recommended
- How it works For the requests that match the condition, the response is produced on TR7; the other requests go to the Backend Services. If the condition is empty, all requests receive the same response.
- Where it is openedLoad Balancer → Actions → Show Content
- Requirement The content in Content Pages; the page does not exceed the buffer size (Buffer Size(kB)) of the vService minus 2 kB
- vService type HTTP
Step-by-Step Configuration
Load Balancer → Profiles → Content Pages → Add is clicked (how to add).
Content Page Name = robots, Content Type = text/plain; in the Content field (in the HTML source mode), one rule is written on each line (static content scenario):
User-agent: *
Disallow: /admin/Add is clicked.
Load Balancer → Conditions → Add is clicked (how to add).
Criteria = Path, Exact match, value /robots.txt. If the same response is to be given to all traffic (e.g. a temporary announcement), no condition is created; steps 4–6 are skipped.
Add is clicked.
Load Balancer → Actions → Add is clicked (how to add).
Action Name is entered, and Action Type = Show content is selected.
- Execution Level = On request (default; it cannot be changed after the save).
- Content Page =
robots(its default is Access Denied Page (English)). - Status Code = 200 (default); 403 for an access block page.
- Conditions = the condition in step 5; left empty for all traffic.
- If Hit Counter (off by default) is turned on, the responses are counted.
Add is clicked.
On the Load Balancer → Load Balancer vService List screen, the HTTP vService is selected and Edit is clicked.
Save is clicked. The change is applied without dropping open connections; in a cluster, it is also sent to the peer device with the default auto-sync (if Manual Sync Mode is on, with Synchronize).
Verification
curl -i https://www.example.com/robots.txt
HTTP/1.1 200 · Content-Type: text/plain; charset=utf-8 · page contentIf the Hit counter is on, the count of the action increases on the Action Hits tab of the vService dashboard; /robots.txt does not appear in the access log of the Backend Service.
The count increases · no request to the Backend ServiceMethod 2: WEB-CLI
- How it works The content, the condition, the action and the vService binding are created with WEB-CLI commands. The example returns a fixed JSON response to the
/healthpath. - Where it is opened TR7 WEB-CLI →
lb page·lb condition·lb action·lb service - Requirement WEB-CLI access; the content is written in a single line and without the
|character (multi-line content is prepared from the interface) - vService type HTTP
Step-by-Step Configuration
Since the content contains double quotes, it is written in single quotes:
lb page add name saglik-json --contentType application/json --content '{"status":"ok"}'If no matching is written, Exact match is used:
lb condition add criteria path query /health --name saglik-yoluThe action binds the condition by its ID, not by its name; lb condition add gives no output when it succeeds; the ID is seen in the id column of the lb condition list output.
--contentProfile takes the name of the page; if --ruleLoc is not written, the action runs at the request stage:
lb action add type showContent name saglik --contentProfile saglik-json --statusCode 200 --cond <condition-id>lb service show <vService>--rules.N replaces the action at that position; the new action is written to the first empty position.
If the vService has two actions (0 and 1), the new action is written to position 2; if it has no actions, --rules.0 is used:
lb service update id <vService> --rules.2 saglikVerification
curl -i https://www.example.com/health
HTTP/1.1 200 · application/json · {"status":"ok"}Common Mistakes
- Forgetting the status code. The default is 200; for a blocking page, a suitable code such as 403 is selected.
- Expecting the subsequent actions to run as well. Show content ends the request; the request actions that come after it in the list do not run for that request (If an action blocks or redirects traffic, do the subsequent actions run?).
- Expecting security headers to be added to this response. Manage HTTP Security Headers and the On response header actions are applied to the responses returning from the Backend Service; they are not added to this response produced by TR7.
- Trying to change the Execution level later. It cannot be changed after the save; a new action is created for a different stage.
- Selecting a large page. If the page exceeds the Buffer size(kB) value of the vService minus 2 kB, the vService configuration cannot be loaded (What is the Content Pages profile; how do I prepare my own HTML page?).
How it is done in the documentation
