Challenge - 5 Problems
Index Directive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What file does Nginx serve by default with this configuration?
Given the following Nginx configuration snippet, which file will Nginx serve when a user requests the root URL
/?Nginx
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html index.htm;
}Attempts:
2 left
💡 Hint
Look at the
index directive to see which files Nginx tries first.✗ Incorrect
The
index directive lists files Nginx looks for in order. Here, it tries index.html first, so it serves /var/www/html/index.html if it exists.📝 Syntax
intermediate2:00remaining
Identify the syntax error in this Nginx index directive
Which option shows the correct syntax for specifying multiple index files in Nginx?
Nginx
index index.html, index.htm index.php;
Attempts:
2 left
💡 Hint
Nginx directives separate values by spaces, not commas or symbols.
✗ Incorrect
The
index directive lists files separated by spaces only. Commas or symbols like '=' or ':' are invalid syntax.❓ optimization
advanced2:00remaining
Optimizing index directive for performance
Which index directive configuration is best for performance when your site primarily uses
index.php and rarely index.html?Attempts:
2 left
💡 Hint
Put the most commonly used file first to reduce file checks.
✗ Incorrect
Nginx checks files in the order listed. Putting
index.php first reduces unnecessary checks, improving performance.🧠 Conceptual
advanced2:00remaining
Effect of missing index directive
What happens if the
index directive is not set in an Nginx server block and a user requests a directory URL?Attempts:
2 left
💡 Hint
Think about what Nginx does when no index file is found and directory listing is off.
✗ Incorrect
Without an
index directive, Nginx does not know which file to serve and if directory listing is disabled, it returns 403 Forbidden.🔧 Debug
expert2:00remaining
Why does Nginx serve a 404 error despite correct index directive?
Given this configuration, why does Nginx return a 404 error when accessing
/?
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
}Attempts:
2 left
💡 Hint
Consider how
try_files works with directories and index files.✗ Incorrect
The
try_files directive checks the exact URI and URI with trailing slash but does not automatically serve index files inside directories. Without additional config, it returns 404.