Performance: Nginx as reverse proxy
This affects server response time and page load speed by efficiently managing client requests before they reach the Flask app.
Use Nginx as reverse proxy forwarding requests to Flask app running with Gunicorn or uWSGI
flask_app.run(host='0.0.0.0', port=5000, debug=False)
| Pattern | Server Load | Response Time | Concurrency Handling | Verdict |
|---|---|---|---|---|
| Flask built-in server only | High under load | Slow with many users | Poor concurrency | [X] Bad |
| Nginx reverse proxy + Gunicorn/uWSGI | Balanced and efficient | Fast response | Handles many connections well | [OK] Good |
proxy_pass.server_name sets domain, listen sets port, root sets file path.http://example.com/api/data?
location /api/ {
proxy_pass http://127.0.0.1:5000/;
}proxy_pass ends with a slash, Nginx appends the full request URI after the location prefix./api/data is forwarded as http://127.0.0.1:5000/api/data.location / {
proxy_pass http://127.0.0.1:8000;
}
Your Flask app runs on port 5000./app/ to your Flask app at http://127.0.0.1:5000/, but remove the /app prefix before forwarding. Which configuration achieves this?proxy_pass URL has no trailing slash, Nginx replaces the matching location prefix with the proxy_pass path.location /app/ and proxy_pass http://127.0.0.1:5000, the /app/ prefix is removed before forwarding.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.Pass the test and this pattern moves unknown