Bird
Raised Fist0
Nginxdevops~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of the stub_status module in nginx?
easy
A. To provide basic server statistics like active connections and requests
B. To enable SSL encryption for secure connections
C. To serve static files faster
D. To balance load between multiple servers

Solution

  1. Step 1: Understand the stub status module role

    The stub status module is designed to show simple server stats such as active connections and request counts.
  2. Step 2: Compare with other options

    SSL encryption, static file serving, and load balancing are handled by other nginx modules, not stub status.
  3. Final Answer:

    To provide basic server statistics like active connections and requests -> Option A
  4. Quick Check:

    Stub status = server stats [OK]
Hint: Stub status shows server stats, not security or file serving [OK]
Common Mistakes:
  • Confusing stub_status with SSL or load balancing modules
  • Thinking stub_status serves files
  • Assuming stub_status handles security
2. Which of the following is the correct way to enable the stub status module inside an nginx configuration location block?
easy
A. location /status { stub_status; }
B. location /status { stub_status on; }
C. location /status { status_stub; }
D. location /status { enable_stub_status; }

Solution

  1. Step 1: Recall stub status syntax

    The stub status module is enabled simply by adding stub_status; inside a location block without extra keywords.
  2. Step 2: Check each option

    location /status { stub_status on; } uses incorrect syntax with stub_status on;. Options C and D use invalid directives.
  3. Final Answer:

    location /status { stub_status; } -> Option A
  4. Quick Check:

    Enable stub_status with just 'stub_status;' [OK]
Hint: Use exactly 'stub_status;' inside location block [OK]
Common Mistakes:
  • Adding 'on' or other keywords after stub_status
  • Using wrong directive names
  • Placing stub_status outside location block
3. Given this nginx configuration snippet:
location /nginx_status {
    stub_status;
    allow 192.168.1.0/24;
    deny all;
}

What will happen if a client from IP 192.168.1.15 accesses /nginx_status?
medium
A. The client will download the nginx configuration file
B. The client will see nginx server statistics
C. The client will be redirected to the homepage
D. The client will get a 403 Forbidden error

Solution

  1. Step 1: Analyze IP access rules

    The configuration allows IPs in 192.168.1.0/24 and denies all others. IP 192.168.1.15 is inside this range, so access is allowed.
  2. Step 2: Understand stub_status output

    With access allowed, the client will see the nginx server statistics page generated by stub_status.
  3. Final Answer:

    The client will see nginx server statistics -> Option B
  4. Quick Check:

    Allowed IP + stub_status = stats page [OK]
Hint: Allowed IPs see stats; others get denied [OK]
Common Mistakes:
  • Ignoring IP allow/deny order
  • Assuming all IPs can access stub_status
  • Thinking stub_status redirects or downloads files
4. You configured nginx with:
location /status {
    stub_status;
}

But when you visit /status, you get a 403 Forbidden error. What is the most likely cause?
medium
A. The stub_status directive is misspelled
B. Nginx does not support stub_status on this version
C. The location block is missing a root directive
D. Access is not restricted by allow/deny rules, so default deny applies

Solution

  1. Step 1: Understand default access behavior

    By default, nginx denies access if no allow/deny rules are set and the stub_status is enabled, causing 403 errors.
  2. Step 2: Check other options

    The stub_status directive is correct, root is not required for stub_status, and most nginx versions support stub_status.
  3. Final Answer:

    Access is not restricted by allow/deny rules, so default deny applies -> Option D
  4. Quick Check:

    No allow/deny means deny by default [OK]
Hint: Always add allow/deny rules to permit stub_status access [OK]
Common Mistakes:
  • Forgetting to add allow rules for trusted IPs
  • Assuming stub_status needs root directive
  • Blaming nginx version without checking
5. You want to monitor nginx server stats securely using stub status. Which configuration snippet correctly enables stub status at /status and restricts access only to localhost?
hard
A. location /status { stub_status; deny 127.0.0.1; allow all; }
B. location /status { stub_status on; allow all; }
C. location /status { stub_status; allow 127.0.0.1; deny all; }
D. location /status { stub_status; allow 0.0.0.0/0; }

Solution

  1. Step 1: Enable stub_status correctly

    Use stub_status; inside the location block without extra keywords.
  2. Step 2: Restrict access to localhost

    Allow only 127.0.0.1 and deny all others to secure access.
  3. Step 3: Evaluate options

    location /status { stub_status; allow 127.0.0.1; deny all; } correctly enables stub_status and restricts access. location /status { stub_status on; allow all; } wrongly uses 'stub_status on;' and allows all. location /status { stub_status; deny 127.0.0.1; allow all; } denies localhost but allows all others, which is insecure. location /status { stub_status; allow 0.0.0.0/0; } allows all IPs.
  4. Final Answer:

    location /status { stub_status; allow 127.0.0.1; deny all; } -> Option C
  5. Quick Check:

    Stub_status + allow localhost + deny others = secure [OK]
Hint: Allow localhost and deny all others for secure stub_status [OK]
Common Mistakes:
  • Using 'stub_status on;' instead of 'stub_status;'
  • Allowing all IPs instead of restricting
  • Denying localhost but allowing others
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard