0
0
Nginxdevops~20 mins

Index directive in Nginx - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Directive Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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;
}
A/var/www/html/index.html
B/var/www/html/default.html
C/var/www/html/index.php
D/var/www/html/home.html
Attempts:
2 left
💡 Hint
Look at the index directive to see which files Nginx tries first.
📝 Syntax
intermediate
2: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;
Aindex index.html, index.htm, index.php;
Bindex index.html index.htm index.php;
Cindex = index.html index.htm index.php;
Dindex: index.html index.htm index.php;
Attempts:
2 left
💡 Hint
Nginx directives separate values by spaces, not commas or symbols.
optimization
advanced
2: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?
Aindex index.php index.html;
Bindex index.html index.php;
Cindex index.htm index.html index.php;
Dindex index.php;
Attempts:
2 left
💡 Hint
Put the most commonly used file first to reduce file checks.
🧠 Conceptual
advanced
2: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?
ANginx returns a 404 Not Found error.
BNginx automatically serves <code>index.html</code> by default.
CNginx lists the directory contents to the user.
DNginx returns a 403 Forbidden error if no index file is found.
Attempts:
2 left
💡 Hint
Think about what Nginx does when no index file is found and directory listing is off.
🔧 Debug
expert
2: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;
    }
}
AThe <code>index</code> directive is ignored inside <code>location</code> blocks.
BThe root path is incorrect and does not contain index files.
CThe <code>try_files</code> directive does not check for index files inside directories.
DNginx requires <code>autoindex on;</code> to serve index files.
Attempts:
2 left
💡 Hint
Consider how try_files works with directories and index files.