Bird
0
0

You want to add gzip compression in Nginx for responses from Django backend but not for static files. Which configuration correctly applies gzip only to proxied requests?

hard📝 Application Q9 of 15
Django - Deployment and Production
You want to add gzip compression in Nginx for responses from Django backend but not for static files. Which configuration correctly applies gzip only to proxied requests?
Agzip off; location /static/ { alias /var/www/static/; } location / { proxy_pass http://127.0.0.1:8000; gzip on; }
Bgzip on; location /static/ { alias /var/www/static/; gzip off; } location / { proxy_pass http://127.0.0.1:8000; }
Cgzip on; location /static/ { alias /var/www/static/; } location / { proxy_pass http://127.0.0.1:8000; gzip off; }
Dgzip off; location /static/ { alias /var/www/static/; gzip on; } location / { proxy_pass http://127.0.0.1:8000; }
Step-by-Step Solution
Solution:
  1. Step 1: Enable gzip globally

    Set gzip on; to enable compression by default.
  2. Step 2: Disable gzip for static files

    Inside location /static/, set gzip off; to exclude static files.
  3. Step 3: Confirm gzip applies to proxied requests

    Requests to / location will have gzip enabled and forwarded to Django.
  4. Final Answer:

    gzip on; location /static/ { alias /var/www/static/; gzip off; } location / { proxy_pass http://127.0.0.1:8000; } -> Option B
  5. Quick Check:

    gzip on globally, off for static = B [OK]
Quick Trick: Enable gzip globally, disable it in static location [OK]
Common Mistakes:
MISTAKES
  • Turning gzip off globally
  • Enabling gzip inside static location
  • Disabling gzip in proxy location

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes