0
0
Nginxdevops~20 mins

Why Nginx handles API routing - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx API Routing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why use Nginx for API routing?

Which reason best explains why Nginx is commonly used to handle API routing?

ANginx can efficiently forward API requests to different backend services based on URL patterns.
BNginx automatically writes API code for backend services.
CNginx stores API data permanently for faster access.
DNginx replaces the need for backend servers entirely.
Attempts:
2 left
💡 Hint

Think about what Nginx does with incoming web requests before they reach backend servers.

💻 Command Output
intermediate
1:30remaining
Nginx API routing configuration output

Given this Nginx config snippet, what will be the output when a request is made to /api/users?

location /api/ {
    proxy_pass http://backend_service;
}
AThe request is forwarded to the backend_service at /api/users.
BNginx returns a 404 Not Found error.
CThe request is served from Nginx's local files.
DNginx returns a 500 Internal Server Error.
Attempts:
2 left
💡 Hint

Consider what proxy_pass does inside a location block.

Configuration
advanced
2:00remaining
Correct Nginx config for API routing with path rewrite

Which Nginx configuration correctly routes requests from /api/v1/ to http://backend_service/v1/ by removing the /api prefix?

A
location /api/v1/ {
    proxy_pass http://backend_service;
}
B
location /api/v1/ {
    proxy_pass http://backend_service/v1/;
}
C
location /api/v1/ {
    proxy_pass http://backend_service/;
}
D
location /api/v1/ {
    proxy_pass http://backend_service/api/v1/;
}
Attempts:
2 left
💡 Hint

Remember that adding a trailing slash to proxy_pass changes how the path is forwarded.

Troubleshoot
advanced
2:00remaining
Why does Nginx return 502 Bad Gateway for API requests?

You configured Nginx to route API requests to a backend service, but Nginx returns a 502 Bad Gateway error. What is the most likely cause?

AThe API request URL is malformed.
BNginx configuration syntax is invalid.
CThe backend service is not running or unreachable from Nginx.
DNginx does not support API routing.
Attempts:
2 left
💡 Hint

502 Bad Gateway means Nginx could not get a valid response from the backend.

Best Practice
expert
2:30remaining
Best practice for securing API routing in Nginx

Which Nginx configuration practice best improves security when routing API requests?

AUse <code>proxy_pass</code> without HTTPS to speed up API calls.
BDisable all logging to avoid exposing API usage data.
CAllow all IP addresses unrestricted access to API routes.
DUse <code>limit_req</code> to limit request rate and <code>auth_basic</code> for simple authentication on API endpoints.
Attempts:
2 left
💡 Hint

Think about how to protect APIs from abuse and unauthorized access.