Fly.io 502 error
I've published my Saas to Fly.io, and the pages load fine, but when it comes to interacting with the backend (for instance, trying to log in, send mail, etc) I get a 502 (bad gateway) error. I have the secrets set (for the client app, PORT = 8080, and for the server app, WASP_SERVER_URL=https://zigozi-server.fly.dev/ and WASP_WEB_CLIENT_URL=https://zigozi-client.fly.dev/).
Also, when I try to log in via Google auth, it takes a while and then crashes at /auth/google/login with the 502 error.
What am I doing wrong?
4 Replies
Hi @Kynetix. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
A 502 (Bad Gateway) error when interacting with your Wasp backend on Fly.io—especially when actions like login or sending mail are involved—typically points to an issue with the backend server not responding correctly to the client or Fly.io's proxy. Based on the knowledge sources, here are the most common causes and troubleshooting steps:
1. Environment Variables and Secrets
You mentioned setting
See: Environment Variables, Google Auth Env Vars You can check which secrets are set on Fly.io with: If any are missing, set them with: 2. Server Health and Logs A 502 error often means the backend server is not running, is crashing, or is not listening on the expected port. - Check Fly.io logs for errors: - Ensure your server is listening on port 8080 (as set by the
See: Troubleshooting deployment 3. CORS and URL Mismatches If
See: Google Auth Setup 5. Redeploy and Restart Sometimes, simply redeploying after correcting secrets or environment variables resolves the issue: or, if deploying manually: See: Manual Deployment --- Summary:
Double-check all required secrets (especially
PORT=8080
, WASP_SERVER_URL
, and WASP_WEB_CLIENT_URL
. Make sure:
- All required secrets are set for the server app, including:
- DATABASE_URL
(PostgreSQL connection string)
- JWT_SECRET
(if using Wasp Auth, must be at least 32 characters)
- WASP_WEB_CLIENT_URL
(URL of your deployed client)
- WASP_SERVER_URL
(URL of your deployed server)
- Any additional secrets for external auth (e.g., GOOGLE_CLIENT_ID
, GOOGLE_CLIENT_SECRET
in .env.server
or as Fly secrets)See: Environment Variables, Google Auth Env Vars You can check which secrets are set on Fly.io with: If any are missing, set them with: 2. Server Health and Logs A 502 error often means the backend server is not running, is crashing, or is not listening on the expected port. - Check Fly.io logs for errors: - Ensure your server is listening on port 8080 (as set by the
PORT
secret).
- Make sure the server is not crashing due to missing environment variables or database connection issues.See: Troubleshooting deployment 3. CORS and URL Mismatches If
WASP_WEB_CLIENT_URL
or WASP_SERVER_URL
are not set correctly, CORS errors or OAuth redirect issues can occur, leading to failed logins or 502s. Double-check that these URLs match your deployed client and server exactly (including <https://
>).
4. Google Auth Specifics
For Google Auth to work in production, you must:
- Set GOOGLE_CLIENT_ID
and GOOGLE_CLIENT_SECRET
as secrets or in .env.server
.
- Ensure your Google OAuth credentials are configured to allow the production URLs (not just localhost).
- Set WASP_SERVER_URL
to your production server URL, as this is used for OAuth redirects.See: Google Auth Setup 5. Redeploy and Restart Sometimes, simply redeploying after correcting secrets or environment variables resolves the issue: or, if deploying manually: See: Manual Deployment --- Summary:
Double-check all required secrets (especially
DATABASE_URL
, JWT_SECRET
, GOOGLE_CLIENT_ID
, GOOGLE_CLIENT_SECRET
), ensure your server is running and listening on the correct port, and verify that your URLs are set correctly. Use flyctl logs
to look for backend errors. If you fix anything, redeploy your app.
If after these steps you still get 502 errors, please provide any error logs from flyctl logs
for more targeted help.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Kynetix, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Did you take a look at your Fly server app logs? There are usualy some hints there 🙂
I was able to resolve it (using warp.dev). Turned out to be missing env variables.
Great stuff!