What is a reverse proxy in the context of web servers?
A reverse proxy is a server that sits between clients and backend servers. It receives client requests and forwards them to the backend server, then sends the server's response back to the client. It helps with load balancing, security, and hiding backend details.
Click to reveal answer
beginner
Why use Nginx as a reverse proxy for a Flask application?
Nginx can handle many client connections efficiently, serve static files quickly, and forward dynamic requests to the Flask app. It improves performance, security, and allows running Flask on a local port hidden from the internet.
Click to reveal answer
intermediate
Which Nginx directive is used to forward requests to the Flask backend?
The proxy_pass directive is used inside a location block to forward client requests to the Flask backend server running on a specific address and port.
Click to reveal answer
intermediate
How does Nginx improve security when used as a reverse proxy?
Nginx can hide the backend server's IP and details, filter bad requests, limit request rates, and handle SSL/TLS encryption. This protects the Flask app from direct attacks and improves overall security.
Click to reveal answer
beginner
What is a common port configuration when using Nginx as a reverse proxy for Flask?
Nginx listens on port 80 (HTTP) or 443 (HTTPS) for client requests, while Flask runs on a local port like 5000. Nginx forwards requests from port 80/443 to Flask's port 5000 internally.
Click to reveal answer
What role does Nginx play when used as a reverse proxy for Flask?
AIt acts as a database for Flask
BIt replaces Flask as the backend application
CIt only serves static files without forwarding requests
DIt forwards client requests to the Flask app and returns responses
✗ Incorrect
Nginx forwards client requests to the Flask backend and sends back the responses, acting as a middleman.
Which Nginx directive forwards requests to the Flask server?
Aproxy_pass
Blisten
Cserver_name
Droot
✗ Incorrect
The proxy_pass directive tells Nginx where to send the incoming requests.
Why is it better to run Flask behind Nginx instead of exposing Flask directly?
AFlask only serves static files
BFlask cannot run on a server without Nginx
CNginx handles many connections efficiently and adds security
DNginx replaces Flask's functionality
✗ Incorrect
Nginx is optimized for handling many connections and adds security features that Flask alone does not provide.
What port does Nginx usually listen on when acting as a reverse proxy for Flask?
A5000
B80 or 443
C8080
D3306
✗ Incorrect
Nginx listens on standard web ports 80 (HTTP) or 443 (HTTPS) and forwards requests to Flask's port.
How does Nginx help with SSL/TLS when used as a reverse proxy?
AIt terminates SSL connections and forwards plain requests to Flask
BIt disables SSL for Flask
CIt encrypts Flask's database
DIt does not support SSL
✗ Incorrect
Nginx handles SSL encryption and then forwards unencrypted requests to Flask, simplifying Flask's setup.
Explain how Nginx acts as a reverse proxy for a Flask application and why this setup is useful.
Think about Nginx as a middleman between users and your Flask app.
You got /5 concepts.
Describe the key Nginx configuration directives needed to set up a reverse proxy for Flask.
Focus on how Nginx forwards requests to Flask.
You got /4 concepts.
Practice
(1/5)
1. What is the main role of Nginx when used as a reverse proxy for a Flask application?
easy
A. Compile Flask Python code into machine code
B. Run the Flask application code directly
C. Forward client requests to the Flask app server
D. Store the Flask app's database
Solution
Step 1: Understand Nginx's role
Nginx acts as a middleman that receives client requests first.
Step 2: Forward requests to Flask app
Nginx sends these requests to the Flask app running on a backend server or port.
Final Answer:
Forward client requests to the Flask app server -> Option C
Quick Check:
Nginx forwards requests = D [OK]
Hint: Nginx passes requests, it does not run Flask code [OK]
Common Mistakes:
Thinking Nginx runs Flask code
Confusing Nginx with database storage
Believing Nginx compiles Python code
2. Which Nginx directive is used to specify the Flask app server URL in the reverse proxy configuration?
easy
A. proxy_pass
B. server_name
C. listen
D. root
Solution
Step 1: Identify directive for backend URL
The directive that tells Nginx where to send requests is proxy_pass.
B. Request is forwarded to http://127.0.0.1:5000/data
C. Request results in 404 error
D. Request is forwarded to http://127.0.0.1:5000/api/data
Solution
Step 1: Understand proxy_pass with trailing slash
Since proxy_pass ends with a slash, Nginx appends the full request URI after the location prefix.
Step 2: Combine location and proxy_pass
Request /api/data is forwarded as http://127.0.0.1:5000/api/data.
Final Answer:
Request is forwarded to http://127.0.0.1:5000/api/data -> Option D
Quick Check:
Trailing slash keeps full path = C [OK]
Hint: Trailing slash in proxy_pass keeps full path [OK]
Common Mistakes:
Removing /api/ from forwarded URL incorrectly
Assuming Nginx serves files locally
Expecting 404 without backend
4. You configured Nginx as below but get a 502 Bad Gateway error. What is the likely cause?
location / {
proxy_pass http://127.0.0.1:8000;
}
Your Flask app runs on port 5000.
medium
A. Nginx is forwarding to wrong port 8000 instead of 5000
B. proxy_pass missing trailing slash causes error
C. Flask app must run on port 8000 for Nginx
D. Nginx cannot proxy to localhost
Solution
Step 1: Check proxy_pass target port
proxy_pass points to port 8000, but Flask runs on 5000, so no backend listens on 8000.
Step 2: Understand 502 Bad Gateway cause
502 means Nginx can't connect to backend server at specified address and port.
Final Answer:
Nginx is forwarding to wrong port 8000 instead of 5000 -> Option A
Quick Check:
Port mismatch causes 502 error = A [OK]
Hint: Match proxy_pass port to Flask app port exactly [OK]
Common Mistakes:
Blaming missing trailing slash for 502
Thinking Flask must run on 8000
Assuming Nginx can't proxy localhost
5. You want Nginx to forward requests from /app/ to your Flask app at http://127.0.0.1:5000/, but remove the /app prefix before forwarding. Which configuration achieves this?
Step 1: Understand proxy_pass without trailing slash
When proxy_pass URL has no trailing slash, Nginx replaces the matching location prefix with the proxy_pass path.
Step 2: Apply to /app/ location
With location /app/ and proxy_pass http://127.0.0.1:5000, the /app/ prefix is removed before forwarding.
Step 3: Check other options
The configuration with proxy_pass http://127.0.0.1:5000/; keeps /app/ prefix, the one with proxy_pass http://127.0.0.1:5000/app/; adds /app/ twice, and location without trailing slash causes mismatch.
Final Answer:
location /app/ {
proxy_pass http://127.0.0.1:5000;
} -> Option B
Quick Check:
proxy_pass without slash removes location prefix = A [OK]
Hint: No trailing slash on proxy_pass removes location prefix [OK]
Common Mistakes:
Adding trailing slash keeps prefix in forwarded URL
Using location without trailing slash causes mismatch
Duplicating /app/ in proxy_pass URL
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.