![]() |
|
Guide Fix Python and Flask 502 Bad Gateway in aaPanel - Printable Version +- AdminsForum (https://adminsforum.com) +-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels) +--- Forum: aaPanel (https://adminsforum.com/Forum-aapanel) +---- Forum: aaPanel Support & Troubleshooting (https://adminsforum.com/Forum-aapanel-support-troubleshooting) +----- Forum: aaPanel Websites & Web Servers Support (https://adminsforum.com/Forum-aapanel-websites-web-servers-support) +----- Thread: Guide Fix Python and Flask 502 Bad Gateway in aaPanel (/Thread-guide-fix-python-and-flask-502-bad-gateway-in-aapanel) |
Fix Python and Flask 502 Bad Gateway in aaPanel - DEV - 10-14-2026 A 502 Bad Gateway response from Nginx usually means it could not get a valid response from the application behind it. For a Flask project, diagnose Gunicorn and the local port before changing DNS or opening firewall ports. Tested lab: aaPanel Free 8.0.7 on Ubuntu 22.04.5. Project af_flask_lab uses Gunicorn on 127.0.0.1:3200 and Nginx serves flask.adminslab.com. We deliberately stopped this disposable project, reproduced public HTTP 502, then started it and recovered HTTP 200. No production website was stopped. Diagnostic workflow diagram: check the app before changing its proxy configuration. 1. Separate the error from a certificate problem Open the hostname and record the actual response. A page saying 502 Bad Gateway is different from a TLS certificate warning, DNS failure or application-generated 500. Do not disable certificate validation to make the test appear successful. 2. Test the local application port From the VPS terminal, replacing 3200 with your actual port: Code: curl -i http://127.0.0.1:3200/
ss -lntp | grep ':3200'
3. Check aaPanel project status and logs Open Website → Python Project, click the project name, then open Project logs. In our lab the log is: Code: /www/wwwlogs/python/af_flask_lab/error.logFor our app, Project information uses:
4. Confirm the right packages are installed Use the selected environment's Python executable, not an unrelated system pip: Code: /www/server/pyporject_evn/af_python_lab/bin/python -m pip show Flask gunicorn
/www/server/pyporject_evn/af_python_lab/bin/python -m pip check5. Compare the Nginx mapping In the project window, open Mapping. Confirm external network mapping is enabled and its detected port matches the actual Gunicorn listener. Ensure the domain is attached to this project in Domain Manager. For our HTTP Gunicorn app, Nginx routes to: Code: proxy_pass http://127.0.0.1:3200;6. Start the app and verify both paths Use the project's Start control after fixing the cause. Wait for the process to initialize, then test localhost and the public hostname again. In our controlled lab test:
If the problem occurs after reboot Check the native Startup option and allow for its advertised 120-second daemon interval. See Python startup and reboot recovery. That guide also documents a lab-version issue where saving project settings removed the SSL listener; verify HTTPS separately after settings changes. When asking for support Share the aaPanel version, startup method, sanitized command, local HTTP result, mapping port and relevant recent log lines. Remove passwords, tokens, cookies, private keys and database connection secrets before posting. AdminsForum lab-tested troubleshooting guide. Illustration is a workflow diagram, not a screenshot of an error page. |