Bird
0
0

You want Nginx to forward requests to Flask only if the URL path starts with /api/, otherwise serve static files. Which Nginx config snippet achieves this?

hard📝 Application Q8 of 15
Flask - Deployment
You want Nginx to forward requests to Flask only if the URL path starts with /api/, otherwise serve static files. Which Nginx config snippet achieves this?
Alocation /api/ { proxy_pass http://127.0.0.1:5000/; } location / { root /var/www/static; }
Blocation / { proxy_pass http://127.0.0.1:5000/; }
Clocation /static/ { proxy_pass http://127.0.0.1:5000/; }
Dlocation /api/ { root /var/www/static; } location / { proxy_pass http://127.0.0.1:5000/; }
Step-by-Step Solution
Solution:
  1. Step 1: Forward /api/ requests to Flask

    Use location /api/ { proxy_pass ... } to send API calls to Flask.
  2. Step 2: Serve other requests as static files

    Use location / { root /var/www/static; } to serve static files for all other paths.
  3. Final Answer:

    location /api/ { proxy_pass http://127.0.0.1:5000/; } location / { root /var/www/static; } -> Option A
  4. Quick Check:

    Separate locations for API and static files [OK]
Quick Trick: Use separate location blocks for API and static files [OK]
Common Mistakes:
MISTAKES
  • Proxying all requests to Flask
  • Serving /api/ as static files
  • Mixing root and proxy_pass in same location

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes