0
0
Djangoframework~20 mins

Nginx as reverse proxy in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nginx Reverse Proxy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What is the main role of Nginx when used as a reverse proxy for a Django app?

Imagine you have a Django app running on a server. You put Nginx in front of it as a reverse proxy. What does Nginx do in this setup?

AIt replaces the Django app and generates HTML pages on its own.
BIt directly runs the Django app code and serves pages to users.
CIt stores the Django app's database and handles data queries.
DIt forwards client requests to the Django app and sends back the app's responses to clients.
Attempts:
2 left
💡 Hint

Think of Nginx as a helpful messenger between users and your Django app.

component_behavior
intermediate
2:00remaining
What happens if Nginx is not configured to forward the correct headers to Django?

You set up Nginx as a reverse proxy but forget to forward the Host header. What problem might occur when Django processes requests?

ADjango will receive the wrong host info and may generate incorrect URLs or fail security checks.
BDjango will crash with a syntax error.
CNginx will stop forwarding requests entirely.
DDjango will ignore the missing header and work normally.
Attempts:
2 left
💡 Hint

Headers tell Django important info about the request origin.

📝 Syntax
advanced
2:30remaining
Which Nginx configuration snippet correctly forwards requests to a Django app running on port 8000?

Choose the Nginx location block that properly proxies requests to Django on localhost:8000.

Django
location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
A
location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
B
location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $remote_addr;
}
C
location / {
    proxy_pass http://localhost:8000/;
    proxy_set_header Host $host;
}
D
location / {
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
}
Attempts:
2 left
💡 Hint

Check for missing semicolons and correct header forwarding.

🔧 Debug
advanced
2:00remaining
Why does Django show a 400 Bad Request error behind Nginx reverse proxy?

You set up Nginx as a reverse proxy for Django. When accessing the site, Django returns a 400 Bad Request error. What is the most likely cause?

ANginx is forwarding requests without the <code>X-Forwarded-For</code> header.
BDjango's ALLOWED_HOSTS setting does not include the domain used in the request.
CThe Django app is not listening on the correct port.
DNginx is not running on the server.
Attempts:
2 left
💡 Hint

Check Django's security settings for allowed domains.

state_output
expert
2:30remaining
What is the value of request.META['REMOTE_ADDR'] in Django when behind Nginx reverse proxy?

Assuming Nginx is configured as a reverse proxy forwarding requests to Django, what IP address will request.META['REMOTE_ADDR'] contain inside Django?

AAlways 127.0.0.1 regardless of client IP.
BThe IP address of the original client making the request.
CThe IP address of the Nginx server acting as reverse proxy.
DAn empty string because Nginx hides the IP.
Attempts:
2 left
💡 Hint

Think about which server actually connects directly to Django.