0
0
Nginxdevops~10 mins

Stub status module in Nginx - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Stub status module
Enable stub_status in nginx.conf
Reload nginx to apply config
Send HTTP request to /nginx_status
nginx returns status info
Parse output for metrics
The stub status module is enabled in nginx config, nginx is reloaded, then a request to the status URL returns server metrics.
Execution Sample
Nginx
location /nginx_status {
    stub_status;
    allow 127.0.0.1;
    deny all;
}

# Then reload nginx
This config block enables the stub status page at /nginx_status, allowing only local access.
Process Table
StepActionInput/RequestOutput/Result
1Add stub_status block to nginx.confN/AConfig updated with /nginx_status location
2Reload nginxnginx -s reloadnginx applies new config without downtime
3Send HTTP GET to http://127.0.0.1/nginx_statusGET /nginx_status200 OK with status text
4Receive stub_status outputN/AActive connections: 1 server accepts handled requests 10 10 20 Reading: 0 Writing: 1 Waiting: 0
5Parse output for metricsStatus textMetrics extracted: active connections=1, accepts=10, handled=10, requests=20, reading=0, writing=1, waiting=0
6EndN/AStatus info ready for monitoring
💡 Stub status output retrieved and parsed successfully
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
nginx.confOriginal configConfig with stub_status blockConfig with stub_status blockConfig with stub_status blockConfig with stub_status blockConfig with stub_status block
nginx processRunning old configRunning old configRunning new configRunning new configRunning new configRunning new config
HTTP responseNoneNoneNone200 OK with status text200 OK with status text200 OK with status text
Parsed metricsNoneNoneNoneNoneExtracted metrics objectExtracted metrics object
Key Moments - 3 Insights
Why do we need to reload nginx after adding the stub_status block?
Because nginx reads its configuration only at startup or reload. The execution_table step 2 shows reload applies the new config without downtime.
Why does the stub_status location allow only 127.0.0.1?
To restrict access to local machine for security. Step 3 shows the request is sent to 127.0.0.1, matching the allow rule.
What does the stub_status output tell us?
It shows live server metrics like active connections and requests handled, as seen in step 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the HTTP response status code at step 3?
A404 Not Found
B200 OK
C500 Internal Server Error
D403 Forbidden
💡 Hint
Check the 'Output/Result' column at step 3 in the execution_table.
At which step does nginx apply the new configuration?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look for the action 'Reload nginx' in the execution_table.
If we remove the 'allow 127.0.0.1;' line, what will likely happen when requesting /nginx_status from localhost?
Anginx will fail to reload
BAccess will be allowed
CAccess will be denied (403 Forbidden)
DThe stub_status output will be empty
💡 Hint
Consider the default deny all rule and the allow line in the config from execution_sample.
Concept Snapshot
Stub status module in nginx:
- Enable with 'stub_status;' inside a location block
- Restrict access with 'allow' and 'deny'
- Reload nginx to apply config
- Access /nginx_status URL to get live server metrics
- Output shows active connections, accepts, handled, requests, reading, writing, waiting
Full Transcript
The stub status module in nginx provides a simple way to get live server metrics. First, you add a location block with 'stub_status;' in the nginx configuration file. You usually restrict access to localhost using 'allow 127.0.0.1;' and 'deny all;'. After saving the config, you reload nginx to apply the changes without downtime. Then, when you send an HTTP GET request to the /nginx_status URL on localhost, nginx returns a plain text status page showing active connections, accepted connections, handled connections, total requests, and current reading, writing, and waiting connections. This output can be parsed by monitoring tools to track nginx performance.