0
0
Nginxdevops~15 mins

Prefix match in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Prefix Match in Nginx Configuration
📖 Scenario: You are setting up a simple web server using Nginx. You want to serve different content based on the URL path prefix.For example, requests starting with /images should serve image files, and requests starting with /videos should serve video files.
🎯 Goal: Configure Nginx to use prefix matching in location blocks to serve different content based on URL path prefixes.
📋 What You'll Learn
Create an Nginx configuration file with a server block
Add a location block that matches the prefix /images
Add a location block that matches the prefix /videos
Set the root directory for each prefix to /var/www/images and /var/www/videos respectively
Print the final Nginx configuration
💡 Why This Matters
🌍 Real World
Web servers often serve different types of content from different folders. Using prefix matching in Nginx helps route requests to the right content folder.
💼 Career
Understanding Nginx configuration and prefix matching is essential for DevOps roles managing web servers and deploying web applications.
Progress0 / 4 steps
1
Create the basic Nginx server block
Create a variable called nginx_config and assign it a string containing the basic Nginx server block with listen 80; and an empty body for server.
Nginx
Need a hint?

Start with a string that contains server { and listen 80; lines.

2
Add a location block for the /images prefix
Add a location /images/ block inside the server block in nginx_config string. Set its alias to /var/www/images/. Use string concatenation or multiline string to add this block.
Nginx
Need a hint?

Inside the server block, add location /images/ { alias /var/www/images/; }.

3
Add a location block for the /videos prefix
Add a location /videos/ block inside the server block in nginx_config string. Set its alias to /var/www/videos/. Append this block after the /images block.
Nginx
Need a hint?

Append location /videos/ { alias /var/www/videos/; } inside the server block.

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

Use print(nginx_config) to show the full configuration.