Stub status module in Nginx - Time & Space Complexity
We want to understand how the time to gather server status grows as more requests come in.
How does nginx handle counting and reporting its activity efficiently?
Analyze the time complexity of the following nginx stub status configuration snippet.
location /nginx_status {
stub_status;
allow 127.0.0.1;
deny all;
}
This snippet enables a simple status page showing active connections and request counts.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: nginx updates counters for connections and requests on each event.
- How many times: Once per connection or request handled by the server.
The time to update counters grows directly with the number of requests.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 counter updates |
| 100 | 100 counter updates |
| 1000 | 1000 counter updates |
Pattern observation: Each new request adds a fixed amount of work to update counters.
Time Complexity: O(n)
This means the time to update and report status grows linearly with the number of requests.
[X] Wrong: "The stub status module scans all connections each time it reports status, so it is slow for many connections."
[OK] Correct: The module uses counters updated incrementally, so it does not scan all connections on each report.
Understanding how simple counters scale with load helps you reason about monitoring tools and server performance in real setups.
"What if the stub status module also tracked detailed per-connection data? How would the time complexity change?"
Practice
stub_status module in nginx?Solution
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.Step 2: Compare with other options
SSL encryption, static file serving, and load balancing are handled by other nginx modules, not stub status.Final Answer:
To provide basic server statistics like active connections and requests -> Option AQuick Check:
Stub status = server stats [OK]
- Confusing stub_status with SSL or load balancing modules
- Thinking stub_status serves files
- Assuming stub_status handles security
location block?Solution
Step 1: Recall stub status syntax
The stub status module is enabled simply by addingstub_status;inside a location block without extra keywords.Step 2: Check each option
location /status { stub_status on; } uses incorrect syntax withstub_status on;. Options C and D use invalid directives.Final Answer:
location /status { stub_status; } -> Option AQuick Check:
Enable stub_status with just 'stub_status;' [OK]
- Adding 'on' or other keywords after stub_status
- Using wrong directive names
- Placing stub_status outside location block
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?Solution
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.Step 2: Understand stub_status output
With access allowed, the client will see the nginx server statistics page generated by stub_status.Final Answer:
The client will see nginx server statistics -> Option BQuick Check:
Allowed IP + stub_status = stats page [OK]
- Ignoring IP allow/deny order
- Assuming all IPs can access stub_status
- Thinking stub_status redirects or downloads files
location /status {
stub_status;
}But when you visit
/status, you get a 403 Forbidden error. What is the most likely cause?Solution
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.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.Final Answer:
Access is not restricted by allow/deny rules, so default deny applies -> Option DQuick Check:
No allow/deny means deny by default [OK]
- Forgetting to add allow rules for trusted IPs
- Assuming stub_status needs root directive
- Blaming nginx version without checking
/status and restricts access only to localhost?Solution
Step 1: Enable stub_status correctly
Usestub_status;inside the location block without extra keywords.Step 2: Restrict access to localhost
Allow only 127.0.0.1 and deny all others to secure access.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.Final Answer:
location /status { stub_status; allow 127.0.0.1; deny all; } -> Option CQuick Check:
Stub_status + allow localhost + deny others = secure [OK]
- Using 'stub_status on;' instead of 'stub_status;'
- Allowing all IPs instead of restricting
- Denying localhost but allowing others
Ready to prove it?
Pass the test and this pattern moves unknown
