0
0
Nginxdevops~30 mins

Wildcard and regex server names in Nginx - Mini Project: Build & Apply

Choose your learning style9 modes available
Wildcard and Regex Server Names in Nginx
📖 Scenario: You are setting up a web server using Nginx. Your goal is to configure server blocks that respond to different website names. Some websites use exact names, some use wildcard patterns, and some use regular expressions to match multiple subdomains.
🎯 Goal: Build an Nginx configuration with three server blocks: one for an exact domain, one using a wildcard server name, and one using a regex server name.
📋 What You'll Learn
Create a server block with an exact server name example.com
Add a server block with a wildcard server name matching all subdomains of example.org
Add a server block with a regex server name matching any subdomain starting with test and ending with .net
Print the full Nginx configuration to verify the setup
💡 Why This Matters
🌍 Real World
Web servers often need to handle many domain names and subdomains. Using wildcard and regex server names in Nginx helps manage these efficiently.
💼 Career
Understanding Nginx server name configuration is essential for DevOps roles managing web infrastructure and deployments.
Progress0 / 4 steps
1
Create exact server name block
Create a server block with server_name example.com; and listen on port 80. Use root /var/www/example.com; inside the block.
Nginx
Need a hint?

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

2
Add wildcard server name block
Add a new server block below the first one with server_name *.example.org; and listen on port 80. Use root /var/www/wildcard; inside this block.
Nginx
Need a hint?

Use server_name *.example.org; to match all subdomains of example.org.

3
Add regex server name block
Add a third server block with server_name ~^test.*\.net$; to match any subdomain starting with test and ending with .net. Listen on port 80 and set root /var/www/regex;.
Nginx
Need a hint?

Use server_name ~^test.*\.net$; for regex matching. Remember to escape the dot.

4
Print the full Nginx configuration
Print the full Nginx configuration by outputting the combined server blocks exactly as written.
Nginx
Need a hint?

Use a print statement to output the full configuration exactly as written.