[{"data":1,"prerenderedAt":42},["ShallowReactive",2],{"blog-post-502-503-504-three-gateway-errors-that-all-look-the-same-and-mean-completely-different-things":3},{"id":4,"meta":5,"title":21,"author":22,"body":26,"introduction":34,"date":35,"tags":36,"category":40,"blog_image":41,"intro":34,"featured":10},1258,{"type":6,"detail_url":7,"html_url":8,"slug":9,"show_in_menus":10,"seo_title":11,"search_description":11,"first_published_at":12,"alias_of":13,"parent":14},"blog.BlogPage","https:\u002F\u002Fwww.staging.doprax.rocks\u002Fd\u002Fapi\u002Fv2\u002Fpages\u002F1258\u002F","https:\u002F\u002Fwww.staging.doprax.rocks\u002Fd\u002Fdoprax-blogs\u002F502-503-504-three-gateway-errors-that-all-look-the-same-and-mean-completely-different-things\u002F","502-503-504-three-gateway-errors-that-all-look-the-same-and-mean-completely-different-things",false,"","2026-06-25T12:11:18.522734Z",null,{"id":15,"meta":16,"title":20},109,{"type":17,"detail_url":18,"html_url":19},"blog.BlogIndexPage","https:\u002F\u002Fwww.staging.doprax.rocks\u002Fd\u002Fapi\u002Fv2\u002Fpages\u002F109\u002F","https:\u002F\u002Fwww.staging.doprax.rocks\u002Fd\u002Fdoprax-blogs\u002F","Doprax Blogs","502, 503, 504: Three gateway errors that all look the same and mean completely different things",{"id":23,"username":24,"full_name":25},5,"Swetlana","Swetlana A",[27],{"type":28,"value":29,"id":33},"section",{"title":30,"content":31,"subsections":32},"The setup that produces these errors","\u003Cp data-block-key=\"y9oek\">Almost every gateway error happens in the same shape. A reverse proxy (nginx, Caddy, Traefik, a load balancer) sits in front, takes the request, and forwards it to your actual application (gunicorn, uvicorn, Node, PHP-FPM, whatever). The proxy is the one writing the error code, because the proxy is the one that tried to reach your app and got an answer it did not like.\u003C\u002Fp>\u003Cp data-block-key=\"fi8g\">That detail matters. When you see a 502, nginx is telling you about a conversation it had with your app. The error page is from nginx. The problem is almost never nginx. Read the codes as nginx reporting on someone else's behavior.\u003C\u002Fp>\u003Ch2 data-block-key=\"1jllj\">502 Bad Gateway: your app answered, and the answer was garbage\u003C\u002Fh2>\u003Cp data-block-key=\"eesqi\">A 502 means the proxy connected to your app, sent the request, and got back something that was not a valid HTTP response. The connection worked. The reply was broken.\u003C\u002Fp>\u003Cp data-block-key=\"thtc\">This is your fault about 90% of the time, and it is usually one of these:\u003C\u002Fp>\u003Cul>\u003Cli data-block-key=\"atjq3\">\u003Cb>Your app crashed mid-request.\u003C\u002Fb> The worker died while handling the request, so the proxy got a closed connection or a partial response. Check your application logs first, not nginx. The stack trace is on the app side.\u003C\u002Fli>\u003Cli data-block-key=\"7q68v\">\u003Cb>You are pointing the proxy at the wrong port.\u003C\u002Fb> Your app is on 8000, nginx is forwarding to 8080. The thing answering on 8080 is not speaking HTTP the way nginx expects, so you get a 502 instead of a clean \"nothing here\".\u003C\u002Fli>\u003Cli data-block-key=\"5b7v8\">\u003Cb>The worker timed out and was killed.\u003C\u002Fb> Gunicorn's default worker timeout is 30 seconds. A request that runs longer gets the worker killed, and the proxy sees a dropped connection. (This one masquerades as a 502 but is really a timeout in disguise, which is why people confuse it with a 504.)\u003C\u002Fli>\u003Cli data-block-key=\"4ojvs\">\u003Cb>A response header got mangled.\u003C\u002Fb> Less common, but a malformed header or an oversized one your app emitted will trip the proxy.\u003C\u002Fli>\u003C\u002Ful>\u003Cp data-block-key=\"fmid4\">How to confirm: hit your app directly, bypassing the proxy.\u003C\u002Fp>\u003Cp data-block-key=\"fnjkh\">If that returns a clean response and the proxy still gives a 502, the problem is in the proxy config (wrong port, wrong socket path). If curl against your app also fails or hangs, the problem is your app. That single command splits the diagnosis in half.\u003C\u002Fp>\u003Ch2 data-block-key=\"5bsml\">503 Service Unavailable: there is nothing to forward to\u003C\u002Fh2>\u003Cp data-block-key=\"f4u6l\">A 503 means the proxy tried to reach your app and there was no app to reach. Nothing is listening. The upstream is down, not broken, just absent.\u003C\u002Fp>\u003Cp data-block-key=\"357u8\">The honest causes:\u003C\u002Fp>\u003Cul>\u003Cli data-block-key=\"4kr7s\">\u003Cb>Your app is not running.\u003C\u002Fb> It crashed and did not restart, or it never started after a deploy, or the process exited on a config error. This is the most common 503 by a wide margin.\u003C\u002Fli>\u003Cli data-block-key=\"7q8ku\">\u003Cb>You restarted it yourself.\u003C\u002Fb> During a deploy, there is a window where the old process is gone and the new one is not ready. Users hitting that window get a 503. This is normal and brief if your deploy is clean, and very much not brief if your new process is crash-looping.\u003C\u002Fli>\u003Cli data-block-key=\"a98u1\">\u003Cb>The proxy is intentionally serving 503.\u003C\u002Fb> Some setups return 503 on purpose when a backend is marked unhealthy or when you have a maintenance page configured. Load balancers do this when every backend fails its health check.\u003C\u002Fli>\u003Cli data-block-key=\"79tja\">\u003Cb>You hit a connection or worker limit.\u003C\u002Fb> The app is up but every worker is busy, so new connections get refused. Raising worker count or adding a queue helps, but first confirm the workers are actually busy and not deadlocked.\u003C\u002Fli>\u003C\u002Ful>\u003Cp data-block-key=\"drs0i\">How to confirm: check whether the process is alive and listening.\u003C\u002Fp>\u003Cp data-block-key=\"bgda5\">If ss shows nothing listening on the port your proxy expects, that is your 503 right there. Start the service, then watch it for 30 seconds to make sure it stays up instead of crash-looping.\u003C\u002Fp>\u003Ch2 data-block-key=\"5jo53\">504 Gateway Timeout: your app is thinking too hard\u003C\u002Fh2>\u003Cp data-block-key=\"4qttp\">A 504 means the proxy reached your app, the app accepted the request, and then the app took longer to respond than the proxy was willing to wait. The connection is fine. The app is just slow on this request.\u003C\u002Fp>\u003Cp data-block-key=\"brq47\">Where the time usually goes:\u003C\u002Fp>\u003Cul>\u003Cli data-block-key=\"e64vo\">\u003Cb>A slow database query.\u003C\u002Fb> The request is blocked on a query that scans a table it should be indexing. This is the single most common real 504. The fix is in your query, not your timeout.\u003C\u002Fli>\u003Cli data-block-key=\"4m95m\">\u003Cb>An external API call with no timeout of its own.\u003C\u002Fb> Your app calls a third-party service, that service hangs, and your request hangs with it until the proxy gives up. Always set a client-side timeout on outbound calls so your app fails fast instead of dragging the proxy down with it.\u003C\u002Fli>\u003Cli data-block-key=\"3s4bj\">\u003Cb>Genuinely heavy work in the request path.\u003C\u002Fb> Image processing, a report that aggregates a million rows, a synchronous job that should be a background task. The request is doing too much before it answers.\u003C\u002Fli>\u003Cli data-block-key=\"e72l3\">\u003Cb>The proxy timeout is just set too low\u003C\u002Fb> for a legitimately long operation. This is the one case where raising the timeout is the right move, and it is rarer than people want it to be.\u003C\u002Fli>\u003C\u002Ful>\u003Cp data-block-key=\"6b8f1\">How to confirm: time the request against your app directly.\u003C\u002Fp>\u003Cp data-block-key=\"cg318\">If that number is bigger than your proxy's timeout, you have found your 504. The question then is whether the request \u003Ci>should\u003C\u002Fi> take that long. Usually it should not, and the answer is a database index or a background job, not a bigger timeout.\u003C\u002Fp>\u003Ch2 data-block-key=\"fpr3f\">Who owns each one\u003C\u002Fh2>\u003Cp data-block-key=\"3tsdl\">ErrorWhat happenedUsually caused byLook here first502App answered, answer was invalidCrash, wrong port, killed workerApp logs503Nothing was listeningApp down, deploy gap, health check failsystemctl status, ss -tlnp504App answered too slowlySlow query, hung external callQuery timing, request profiling\u003C\u002Fp>\u003Cp data-block-key=\"a89df\">The pattern across all three: the proxy is the messenger, the app is almost always the subject. Read the proxy logs to learn \u003Ci>which\u003C\u002Fi> error you have, then go straight to the application side to fix it. The number of hours lost to debugging nginx when the bug was a missing database index is not small.\u003C\u002Fp>\u003Ch2 data-block-key=\"frddp\">The one config that prevents the most pain\u003C\u002Fh2>\u003Cp data-block-key=\"bicet\">Set timeouts that match reality at every layer, and make them agree. If your app's worker timeout is 30 seconds but your proxy waits 60, the proxy will report a 502 (worker killed) instead of a clean 504 (timeout), and you will spend the first ten minutes debugging the wrong error. Make the proxy timeout slightly longer than your app's worker timeout so the slow case surfaces as a 504, which tells you the truth: the app was slow, not broken.\u003C\u002Fp>\u003Cp data-block-key=\"adtbk\">That alignment alone turns a category of confusing 502s into honest 504s, and an honest error code is half the fix.\u003C\u002Fp>\u003Cp data-block-key=\"amula\">On a Doprax ProVM you control the whole stack, proxy and app on the same box, so there is no mystery middle layer adding its own timeouts and its own error pages between you and your code.\u003C\u002Fp>",[],"3e08ff7b-d0ba-4220-85b3-932b5629aa02","\u003Cp data-block-key=\"c3512\">A 502, a 503, and a 504 all show up as the same thing to your users: a blank page where your app used to be. To you, they are three different bugs with three different owners. One is almost always your application. One is usually you taking the server down on purpose, or your server falling over. One is something taking too long, which might be your code or might be the network between two machines you do not control.\u003C\u002Fp>\u003Cp data-block-key=\"cof77\">Getting them confused costs you time. You restart the wrong service, you stare at the wrong logs, you blame the wrong layer. So here is the short version, then the long one.\u003C\u002Fp>\u003Cp data-block-key=\"br18i\">The quick rule: \u003Cb>502 means the upstream answered wrong. 503 means the upstream is not there. 504 means the upstream answered too slowly.\u003C\u002Fb> \"Upstream\" is whatever your reverse proxy is forwarding to, usually your app server.\u003C\u002Fp>","2026-06-24",[37,38,39],"502 error","503 error","504 error","updates","\u002Fd\u002Fmedia\u002Foriginal_images\u002F502_error_code_503_504_doprax.png",1792480192554]