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?
Think of Nginx as a helpful messenger between users and your Django app.
Nginx acts as a middleman that receives requests from users, passes them to the Django app, then sends the app's responses back to users. It does not run the Django code or store data.
You set up Nginx as a reverse proxy but forget to forward the Host header. What problem might occur when Django processes requests?
Headers tell Django important info about the request origin.
If Nginx does not forward the Host header, Django may not know the correct domain name. This can cause wrong URL generation or security issues like CSRF failures.
Choose the Nginx location block that properly proxies requests to Django on localhost:8000.
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;
}Check for missing semicolons and correct header forwarding.
Option A includes all necessary headers and proper syntax with semicolons. Option A misses a semicolon after proxy_pass. Option A adds a trailing slash which can change URL behavior. Option A forwards wrong header for Host.
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?
Check Django's security settings for allowed domains.
Django returns 400 Bad Request if the Host header in the request is not in ALLOWED_HOSTS. Behind Nginx, if the domain is missing from ALLOWED_HOSTS, Django rejects the request.
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?
Think about which server actually connects directly to Django.
When Nginx proxies requests, Django sees the connection coming from Nginx's IP, not the original client. To get the real client IP, Django must read the X-Forwarded-For header.