0
0
Nginxdevops~15 mins

Root directive in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Configuring the Root Directive in Nginx
📖 Scenario: You are setting up a simple web server using Nginx. You want to serve static files from a specific folder on your computer.
🎯 Goal: Learn how to configure the root directive in Nginx to specify the folder where your website files are located.
📋 What You'll Learn
Create a basic Nginx server block configuration
Set the root directive to the correct folder path
Use the location / block to serve files from the root directory
Print the final configuration to verify the setup
💡 Why This Matters
🌍 Real World
Web servers use the <code>root</code> directive to know where to find the website files to serve to visitors.
💼 Career
Understanding Nginx configuration is essential for DevOps roles that manage web servers and deploy web applications.
Progress0 / 4 steps
1
Create the basic server block
Create a variable called nginx_config and assign it a string that starts with server { and includes listen 80; and server_name localhost; inside the block.
Nginx
Need a hint?

Remember to use triple quotes or escape newlines to create multi-line strings.

2
Add the root directive
Add a line inside the server block in nginx_config that sets the root directive to /var/www/html. Use the exact text root /var/www/html;.
Nginx
Need a hint?

The root directive tells Nginx where to find your website files.

3
Add a location block
Add a location / block inside the server block in nginx_config with the exact text location / { try_files $uri $uri/ =404; } to serve files from the root directory.
Nginx
Need a hint?

The location / block tells Nginx how to handle requests to the root URL.

4
Print the final configuration
Write a print statement to display the value of nginx_config.
Nginx
Need a hint?

Use print(nginx_config) to show the configuration.