0
0
Nginxdevops~20 mins

Why URL manipulation handles routing in Nginx - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
URL Routing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does URL manipulation affect routing in nginx?

In nginx, what is the main reason URL manipulation is used to handle routing?

AIt allows nginx to decide which backend server or resource to serve based on the URL path.
BIt compresses the URL to reduce bandwidth usage.
CIt encrypts the URL to secure the connection between client and server.
DIt changes the URL to a random string to prevent caching.
Attempts:
2 left
💡 Hint

Think about how nginx uses the URL path to find the right content or service.

💻 Command Output
intermediate
2:00remaining
What is the output of this nginx rewrite rule?

Given this nginx configuration snippet:

location /app/ {
  rewrite ^/app/(.*)$ /$1 break;
}

What will be the rewritten URL when a client requests /app/dashboard?

Nginx
location /app/ {
  rewrite ^/app/(.*)$ /$1 break;
}
A/dashboard
B/app//dashboard
C/app/dashboard
D/app
Attempts:
2 left
💡 Hint

Look at the rewrite regex and what it captures.

Configuration
advanced
2:00remaining
Which nginx config correctly routes URLs with query strings?

You want nginx to route requests starting with /search to a backend server, preserving the query string. Which configuration snippet does this correctly?

A
location /search {
  proxy_pass http://backend/search?query=$args;
}
B
location /search {
  proxy_pass http://backend/search;
}
C
location /search {
  proxy_pass http://backend/search?$args;
}
D
location /search {
  proxy_pass http://backend/search$is_args$args;
}
Attempts:
2 left
💡 Hint

Remember how nginx appends query strings with $is_args and $args.

Troubleshoot
advanced
2:00remaining
Why does this nginx rewrite cause a redirect loop?

Consider this nginx config:

location /old/ {
  rewrite ^/old/(.*)$ /new/$1 permanent;
}
location /new/ {
  rewrite ^/new/(.*)$ /old/$1 permanent;
}

What is the cause of the redirect loop?

Anginx does not support rewrite rules inside location blocks.
BBoth locations rewrite URLs to each other permanently, causing infinite redirects.
CThe 'permanent' flag is missing in one rewrite causing mismatch.
DThe regex patterns are invalid and cause nginx to crash.
Attempts:
2 left
💡 Hint

Think about what happens when a URL matches /old/ and then /new/ repeatedly.

Best Practice
expert
2:00remaining
What is the best practice for handling trailing slashes in nginx routing?

You want to ensure URLs with or without trailing slashes are routed consistently to avoid duplicate content. Which nginx configuration snippet follows best practice?

A
location /app {
  try_files $uri $uri/ =404;
}
B
location /app/ {
  rewrite ^/(.*)/$ /$1 permanent;
}
C
location /app/ {
  rewrite ^/(.*[^/])$ /$1/ permanent;
}
D
location /app {
  rewrite ^/(.*)/$ /$1/ permanent;
}
Attempts:
2 left
💡 Hint

Consider how to redirect URLs without trailing slash to ones with trailing slash.