In nginx, what is the main reason URL manipulation is used to handle routing?
Think about how nginx uses the URL path to find the right content or service.
nginx uses the URL path to route requests to the correct backend or serve the right file. Manipulating the URL helps it match patterns and decide where to send the request.
Given this nginx configuration snippet:
location /app/ {
rewrite ^/app/(.*)$ /$1 break;
}What will be the rewritten URL when a client requests /app/dashboard?
location /app/ {
rewrite ^/app/(.*)$ /$1 break;
}Look at the rewrite regex and what it captures.
The rewrite rule captures everything after '/app/' and rewrites the URL to '/' plus the captured part. So '/app/dashboard' becomes '/dashboard'.
You want nginx to route requests starting with /search to a backend server, preserving the query string. Which configuration snippet does this correctly?
Remember how nginx appends query strings with $is_args and $args.
Option D uses $is_args which adds '?' if there are arguments, and $args to append the original query string, preserving it correctly.
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?
Think about what happens when a URL matches /old/ and then /new/ repeatedly.
Each rewrite sends the URL to the other location with a permanent redirect, causing the browser to bounce back and forth endlessly.
You want to ensure URLs with or without trailing slashes are routed consistently to avoid duplicate content. Which nginx configuration snippet follows best practice?
Consider how to redirect URLs without trailing slash to ones with trailing slash.
Option C redirects URLs missing a trailing slash to the same URL with a trailing slash, ensuring consistent URL format and avoiding duplicate content.