3 months ago
502 Bad Gateway for all the API, port configured as 8080
9 Replies
3 months ago
A 502 Bad Gateway means our proxy cannot reach your application. Ensure your application is binding to host 0.0.0.0 and listening on the port defined by the PORT environment variable that we inject automatically, and if you have manually set PORT to 8080, make sure the target port on your domain also matches. More details are in our troubleshooting guide.
Status changed to Awaiting User Response Railway • 3 months ago
3 months ago
Port is configured as per the documentation itself still getting same error
Status changed to Awaiting Railway Response Railway • 3 months ago
3 months ago
Can you try to bind it directly to 0.0..0.0 instead?
# Python (FastAPI/Flask/etc.)
app.run(host="0.0.0.0", port=8080)
// Node.js
app.listen(8080, "0.0.0.0")
or use the injected port railway gives:
const port = process.env.PORT || 8080; app.listen(port, "0.0.0.0");
3 months ago
If you've already configured your app to listen on 0.0.0.0, something I'd try as a sanity check is to change the port your application is listening on to 3000, along with the port your URL is mapped to.
Railway
A 502 Bad Gateway means our proxy cannot reach your application. Ensure your application is binding to host `0.0.0.0` and listening on the port defined by the `PORT` environment variable that we inject automatically, and if you have manually set `PORT` to 8080, make sure the [target port on your domain](https://docs.railway.com/networking/public-networking#port-variable) also matches. More details are in our [troubleshooting guide](https://docs.railway.com/networking/troubleshooting/application-failed-to-respond).
3 months ago
3 months ago
const port = parseInt(process.env.PORT || '3000', 10);
log(` Binding to 0.0.0.0:${port}...`);
try {
await app.listen(port, '0.0.0.0');
log('');
log('');
log('Available endpoints:');
log(` Health: http://0.0.0.0:${port}/api/v1/health`);
log(` Docs: http://0.0.0.0:${port}/api/docs`);
log('');
log('Waiting for requests...');
}
Here's the code Attachments
3 months ago
If the PORT env variable is resolving to 8080 (check your logs to verify), then you need to change the port your url is mapped to in the Networking section in your Service Settings to 8080 as well, because it's currently set to 3000 as shown in the image you provided.
3 months ago
Or, you can just hard-code your port to 3000 in your code instead. const port = 3000;
3 months ago
Tried hardcoding still not working looks like some other issue. Is there a way railway team can help