0
0
Nginxdevops~30 mins

Directives and blocks in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Directives and Blocks in Nginx Configuration
📖 Scenario: You are setting up a simple web server using Nginx. To do this, you need to write a configuration file that tells Nginx how to handle requests.In Nginx, configuration is done using directives and blocks. Directives are instructions, and blocks group related directives together.
🎯 Goal: Build a basic Nginx configuration file with a http block containing a server block. Inside the server block, set the server name and root directory using directives.
📋 What You'll Learn
Create an http block
Inside http, create a server block
Inside server, add a server_name directive with value example.com
Inside server, add a root directive with value /var/www/html
Print the complete configuration at the end
💡 Why This Matters
🌍 Real World
Nginx is a popular web server used to serve websites and applications. Understanding directives and blocks helps you configure it to handle web traffic correctly.
💼 Career
Many DevOps and system administrator roles require writing and managing Nginx configuration files to deploy and maintain web services.
Progress0 / 4 steps
1
Create the http block
Write the opening and closing lines for an http block in Nginx configuration. Use http { to start and } to end the block.
Nginx
Need a hint?

The http block groups all HTTP-related settings.

2
Add a server block inside http
Inside the existing http block, add a server block using server { and } lines.
Nginx
Need a hint?

The server block defines settings for one website or domain.

3
Add server_name and root directives inside server
Inside the server block, add the directive server_name example.com; and the directive root /var/www/html; each on its own line.
Nginx
Need a hint?

The server_name directive sets the domain name. The root directive sets the folder for website files.

4
Print the complete Nginx configuration
Print the entire Nginx configuration stored in a variable called nginx_config.
Nginx
Need a hint?

Use print(nginx_config) to display the configuration.