Imagine you have a Flask app running on port 5000. You want users to access it via port 80 using Nginx. What does Nginx do in this setup?
Think about how Nginx acts as a middleman between the user and the Flask app.
Nginx listens on port 80 and forwards requests to the Flask app running on port 5000. It then sends the Flask app's response back to the user, acting as a reverse proxy.
You configured Nginx as a reverse proxy but forgot to pass the Host header. How does this affect your Flask app?
Consider how Flask uses the Host header for URL building and routing.
If Nginx does not forward the Host header, Flask may generate URLs with wrong hosts or fail to route requests properly because it relies on this header.
Choose the Nginx server block that properly proxies requests to a Flask app running on port 5000.
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Look for correct syntax including semicolons and proper proxy headers.
Option A correctly sets proxy_pass with a semicolon and includes necessary headers with proper syntax. Other options miss semicolons or headers.
You set proxy_pass to http://localhost:6000 but your Flask app runs on port 5000. What will a user see when accessing your site?
Think about what happens when Nginx tries to forward requests to a non-listening port.
If Nginx cannot reach the upstream server, it returns a 502 Bad Gateway error to the client indicating a bad connection.
After setting up Nginx as a reverse proxy, your Flask app logs show all client IPs as 127.0.0.1. What is the cause?
Check how Nginx passes client IP information to backend apps.
By default, Nginx proxies requests from itself, so Flask sees Nginx's IP (127.0.0.1). To get real client IP, Nginx must forward headers like X-Real-IP and Flask must read them.