Overview - Root directive
What is it?
The root directive in nginx sets the base directory from which files are served for a particular location or server block. It tells nginx where to look on the file system when a client requests a resource. This directive is essential for serving static files like HTML, images, or scripts. Without it, nginx wouldn't know where to find the files to send back to users.
Why it matters
Without the root directive, nginx cannot locate the files requested by users, causing errors like 404 Not Found. This would make websites or applications inaccessible or broken. The root directive solves the problem of mapping web requests to actual files on the server, enabling nginx to serve content efficiently and correctly.
Where it fits
Before learning the root directive, you should understand basic nginx configuration structure, including server and location blocks. After mastering root, you can learn about alias directive, try_files, and advanced location matching to control how nginx serves files and handles requests.