0
0
Nginxdevops~5 mins

Index directive in Nginx - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the index directive in nginx?
The index directive tells nginx which file to serve when a directory is requested. It looks for the specified files in order and serves the first one it finds.
Click to reveal answer
beginner
How does nginx behave if the index directive is not set and a directory is requested?
If the index directive is not set, nginx uses the default value index.html and attempts to serve that file for a directory request. If the file does not exist, it may return a 403 Forbidden error or list the directory contents if autoindex is enabled.
Click to reveal answer
beginner
Example: <br> index index.html index.htm; <br> What does this configuration mean?
This means nginx will first look for a file named index.html in the requested directory. If it is not found, it will look for index.htm. It serves the first file found.
Click to reveal answer
intermediate
Can the index directive accept multiple file names? How does nginx use them?
Yes, the index directive can list multiple file names separated by spaces. Nginx checks them in order and serves the first existing file it finds in the directory.
Click to reveal answer
intermediate
Where in the nginx configuration file can the index directive be placed?
The index directive can be placed inside the http, server, or location blocks to control default files at different levels.
Click to reveal answer
What does the nginx index directive do?
ASpecifies default files to serve when a directory is requested
BDefines the server's IP address
CSets the maximum file upload size
DConfigures SSL certificates
If index index.html index.htm; is set, and both files exist, which one will nginx serve?
Aindex.htm
BBoth files simultaneously
Cindex.html
DIt will return an error
Where can the index directive be used in nginx configuration?
AOnly inside <code>server</code> block
BInside <code>http</code>, <code>server</code>, or <code>location</code> blocks
COnly inside <code>http</code> block
DOnly inside <code>location</code> block
What happens if no file listed in the index directive exists in the directory?
ANginx lists the directory contents if autoindex is enabled
BNginx serves the first file anyway
CNginx serves a 404 Not Found error
DNginx restarts automatically
Can the index directive accept only one file name?
ANo, it requires at least two file names
BYes, but only if the file is named index.html
CNo, it only accepts directories
DYes, it can accept one or more file names
Explain how the nginx index directive works when a user requests a directory URL.
Think about what nginx does when you visit a folder on a website.
You got /4 concepts.
    Describe where you can place the index directive in nginx configuration and why placement matters.
    Consider different levels of configuration in nginx.
    You got /4 concepts.