📖 Scenario: You are managing a web server running Nginx. To keep track of how well your server is performing, you want to enable a simple status page that shows basic metrics like active connections and requests handled.This helps you quickly see if your server is busy or if there are any issues.
🎯 Goal: Enable and configure the Nginx stub_status module to create a status page accessible at /nginx_status. This page will show live server statistics.
📋 What You'll Learn
Create a new server block listening on port 8080
Add a location /nginx_status that uses the stub_status module
Allow access to the status page from localhost only
Test the configuration and display the status page output
💡 Why This Matters
🌍 Real World
Nginx stub_status is used by system administrators to quickly check server health and traffic without installing extra software.
💼 Career
Knowing how to enable and secure Nginx status pages is a common task for DevOps engineers and system administrators to monitor web servers.
Progress0 / 4 steps
1
Create a new server block listening on port 8080
Write a server block in Nginx configuration with listen 8080; and server_name localhost;.
Nginx
Hint
Use server { ... } block with listen 8080; and server_name localhost;.
2
Add a location /nginx_status that uses the stub_status module
Inside the existing server block, add a location /nginx_status block with stub_status; directive.
Nginx
Hint
Use location /nginx_status { stub_status; } inside the server block.
3
Allow access to the status page from localhost only
Inside the location /nginx_status block, add directives to allow access only from 127.0.0.1 and deny all others.
Nginx
Hint
Use allow 127.0.0.1; and deny all; inside the location block.
4
Test the configuration and display the status page output
Run nginx -t to test the configuration, then reload Nginx. Finally, use curl http://127.0.0.1:8080/nginx_status to display the status page output.
Nginx
Hint
Use nginx -t to test, nginx -s reload to reload, and curl http://127.0.0.1:8080/nginx_status to see the status.
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
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 A
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
Step 1: Recall stub status syntax
The stub status module is enabled simply by adding stub_status; inside a location block without extra keywords.
Step 2: Check each option
location /status { stub_status on; } uses incorrect syntax with stub_status on;. Options C and D use invalid directives.
Final Answer:
location /status { stub_status; } -> Option A
Quick Check:
Enable stub_status with just 'stub_status;' [OK]
Hint: Use exactly 'stub_status;' inside location block [OK]
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
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 B
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
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 D
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
Step 1: Enable stub_status correctly
Use stub_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.