custom 502 error page?

dvdmrn
HOBBY

10 days ago

Is it possible to make a custom 502 "bad gateway" error page? Instead of the ghost train with Go to Railway?

$10 Bounty

1 Replies

dvdmrn
HOBBY

10 days ago

N/A


10 days ago

Hello,

Not natively, no. You would need to run your own proxy that returns your own HTML when the downstream fails to respond.



10 days ago

No, it would need to be an external proxy, like Caddy.

The middleware won't work since Railway's 502 page is shown when your application doesn't respond, and if your app isn't responding, then it can't send the custom response.


dvdmrn
HOBBY

10 days ago

ah ok thanks!


saimprojects
HOBBY

7 days ago

Yes, it’s absolutely possible to make a custom 502 “Bad Gateway” error page on Railway instead of their default ghost train page. But the trick is that the 502 page is served by Railway itself (before your app is hit), so you can't directly override it on their side. However, you can simulate or handle 502-like responses inside your app by doing the following:

2 Ways to Show a Custom 502 Page

1. Use a Reverse Proxy (Recommended for Control)

  • Place a reverse proxy (like Nginx or Caddy) in front of your Django app.

  • Configure Nginx’s error_page directive to display a custom HTML page for 502 errors:

    CopyEdit

    error_page 502 /custom_502.html; location = /custom_502.html { root /usr/share/nginx/html; internal; }

  • Deploy this reverse proxy along with your app on Railway.

2. Serve a Custom 502 Page from Django (Fallback Simulation)

While you can’t replace Railway's own error page, you can catch upstream failures (like DB errors) and return a custom template that looks like a 502 page:

CopyEdit

from django.shortcuts import render from django.http import HttpResponseServerError def custom_502(request): return HttpResponseServerError(render(request, "502.html"))

Then, in urls.py:

CopyEdit

handler502 = "yourapp.views.custom_502"

Note: This will only trigger for Django-side 502-like errors, not when Railway itself shows 502 because the container is down.

Real Solution for Railway's Default 502

To truly avoid Railway’s default ghost train 502:

  • Ensure your web service is always running and responding quickly (no cold start).

  • Add a small "uptime monitor" (like UptimeRobot) to keep the service alive.

  • Use a proxy layer (Cloudflare Workers, Vercel Edge, or Nginx) to catch Railway errors and display your custom 502 page instead.