0
0
Flaskframework~20 mins

Nginx as reverse proxy in Flask - 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
1:30remaining
What is the main role of Nginx when used as a reverse proxy for a Flask app?

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?

ANginx forwards incoming requests on port 80 to the Flask app on port 5000 and sends back the Flask app's response to the client.
BNginx replaces the Flask app and handles all Python code execution.
CNginx runs the Flask app internally and serves static files only.
DNginx blocks all requests except those from localhost.
Attempts:
2 left
💡 Hint

Think about how Nginx acts as a middleman between the user and the Flask app.

component_behavior
intermediate
1:30remaining
What happens if Nginx is not configured to forward the Host header to the Flask app?

You configured Nginx as a reverse proxy but forgot to pass the Host header. How does this affect your Flask app?

AThe Flask app will crash immediately with a server error.
BThe Flask app may receive incorrect Host information, causing URL generation or routing issues.
CNginx will automatically add the Host header, so nothing changes.
DThe Flask app will ignore the Host header and work normally.
Attempts:
2 left
💡 Hint

Consider how Flask uses the Host header for URL building and routing.

📝 Syntax
advanced
2:00remaining
Which Nginx configuration snippet correctly sets up a reverse proxy to a Flask app on localhost:5000?

Choose the Nginx server block that properly proxies requests to a Flask app running on port 5000.

Flask
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;
    }
}
A
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;
}
B
location / {
    proxy_pass http://localhost:5000/
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
}
C
location / {
    proxy_pass http://localhost:5000
    proxy_set_header Host $host
}
D
location / {
    proxy_pass http://localhost:5000;
    proxy_set_header Host;
    proxy_set_header X-Real-IP;
}
Attempts:
2 left
💡 Hint

Look for correct syntax including semicolons and proper proxy headers.

state_output
advanced
1:30remaining
What is the visible effect if Nginx reverse proxy is misconfigured with an incorrect upstream address?

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?

ANginx serves a default welcome page instead of the Flask app.
BThe Flask app loads normally without any issues.
CThe browser shows a 502 Bad Gateway error because Nginx cannot connect to the Flask app.
DThe browser shows a 404 Not Found error from Flask.
Attempts:
2 left
💡 Hint

Think about what happens when Nginx tries to forward requests to a non-listening port.

🔧 Debug
expert
2:00remaining
Why does your Flask app behind Nginx reverse proxy always see the client IP as 127.0.0.1?

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?

ANginx is blocking the client IP and replacing it with 127.0.0.1 for security.
BFlask is ignoring all headers and always uses 127.0.0.1 by default.
CThe client is actually connecting from localhost, so IP is correct.
DNginx is not forwarding the original client IP in the X-Real-IP or X-Forwarded-For headers, so Flask sees the proxy's IP.
Attempts:
2 left
💡 Hint

Check how Nginx passes client IP information to backend apps.