Status codes · one code504Gateway Timeout

What a 504 Gateway Timeout response means, who is at fault, what a visitor should do and what the server owner should do.

Open the reference on this code
What is happening

The page loads for a long time and then gives up

upstream timed out (110: Connection timed out) while reading response header from upstream

The upstream is alive and accepted the connection, but no answer arrived in time — sixty seconds by default in nginx. There is usually a single slow step behind it: a heavy database query, a call to an external API without a timeout, or a report computed synchronously.

Code
Who is at faultServer error
Class5xx Server error
01

What to do

If it is someone else's site

Try again later: the request arrived but the server did not answer in time. If the 504 keeps happening on the same heavy page — a large report, say — it is not your connection, and waiting longer will not help.

If it is your server

Do not raise proxy_read_timeout first: that hides the symptom and leaves the request hanging longer, holding a connection. Find the slow step first — in the application log, by response time — and decide whether it is honestly long. If it is, move that work to the background and deliver the result separately; raise the limit only for it rather than for the whole server.

02

Easily confused with

502Bad Gateway

there was no connection at all: the upstream is down or listening elsewhere.

502
408Request Timeout

the mirror case — there it is the client that failed to finish sending in time.

408
503Service Unavailable

the server refused immediately instead of staying silent until the timeout.

503
03

How to check

curl -o /dev/null -s -w '%{time_total}\n' http://127.0.0.1:3000/report

how many seconds the upstream really takes, with no proxy involved

grep 'upstream timed out' /var/log/nginx/error.log | tail -n 20

which addresses hit the timeout most often

Find another code

The reference holds sixty-four codes searchable by number, name and meaning — plus a breakdown of confusing pairs such as 401 and 403.

Open the reference on this codeAll codes

Updated

«» added to favorites