0
0
Nginxdevops~20 mins

Exact match (=) in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Configuring Exact Match (=) in Nginx Location Blocks
📖 Scenario: You are setting up a simple web server using Nginx. You want to serve a special page only when the user visits the exact URL /special. For all other URLs, a default page should be served.
🎯 Goal: Learn how to use the exact match = modifier in Nginx location blocks to serve content only for an exact URL path.
📋 What You'll Learn
Create a basic Nginx server block listening on port 80
Add a location block with exact match = /special to serve a special page
Add a default location / block to serve a default page
Use return directives to send simple text responses
💡 Why This Matters
🌍 Real World
Web servers often need to serve special content for exact URLs, such as landing pages or API endpoints. Using exact match locations ensures precise control over which content is served.
💼 Career
Understanding Nginx location matching is essential for DevOps engineers and system administrators managing web servers and optimizing routing rules.
Progress0 / 4 steps
1
Create the basic server block
Create a server block that listens on port 80 and has a server_name of localhost.
Nginx
Need a hint?

Use server { ... } block with listen 80; and server_name localhost;.

2
Add exact match location for /special
Inside the server block, add a location block with exact match modifier = /special that returns status 200 with the text Special Page.
Nginx
Need a hint?

Use location = /special { return 200 'Special Page'; } inside the server block.

3
Add default location block
Add a default location / block inside the server block that returns status 200 with the text Default Page.
Nginx
Need a hint?

Use location / { return 200 'Default Page'; } inside the server block.

4
Test the configuration output
Print the exact text that Nginx would return when visiting /special and /other URLs using the return directives you configured.
Nginx
Need a hint?

Print Special Page and Default Page on separate lines to simulate Nginx responses.