The 504 error code means a server acting as an intermediary did not receive a timely response from the next server it needed. When a proxy is in the path, the timeout can be between your client and the proxy, the proxy and your 4G route, or the proxy and the website.
What a 504 means
HTTP 504 is a server error response. The HTTP specification defines it as a proxy or gateway not receiving a timely response from an upstream server needed to complete the request. “Upstream” means the next service in the request path, not always the website you typed into the browser.
That distinction matters. A 504 may be generated by a reverse proxy waiting for an application, by a forward proxy waiting for a destination, by a load balancer waiting for a backend, or by an intermediary waiting for DNS or network activity. The status alone cannot tell you which component is slow.
For example, this path may contain five separate conversations:
| Hop | Conversation | What can time out |
|---|---|---|
| 1 | Browser or script → proxy endpoint | Proxy host, port, authentication, or the first network connection |
| 2 | Proxy router → your Linux box | Outbound connection, routing, or box availability |
| 3 | Linux box → 4G dongle and carrier network | Radio signal, modem session, DNS, or data connection |
| 4 | 4G address → destination website | Destination firewall, slow TLS handshake, or a route that stops responding |
| 5 | Destination web server → its application or database | Slow query, blocked worker, queue, or application timeout |
The response can look identical to a visitor even though the repair is completely different. The HTTP 504 definition in RFC 9110 is the starting point; your logs and controlled tests identify the failing hop.
What you need before troubleshooting
Collect one failing URL, the approximate time of the failure, the HTTP method, and whether the request was made directly or through a proxy. For a proxy request, record the proxy hostname, port, protocol, and the specific dongle or route used. Do not paste usernames, passwords, session tokens, or full proxy URLs into a ticket or public log.
You should also have:
- A second network, such as a phone hotspot, for comparison.
- Shell access to the machine that owns the proxy route, if you manage it.
- Access to reverse-proxy, load-balancer, web-server, and application logs if you own the destination.
- A known-good URL on the same destination, such as a small health endpoint.
- A request ID, if the service adds one to the response headers.
Write down the timestamp with its time zone. A 504 in an access log is much easier to match when you know whether the client reported 14:05 UTC or 14:05 local time.
Step 1: Confirm the 504 and check whether it is repeatable
Why: A one-off timeout and a consistent timeout need different responses. Retrying a safe read can reveal a short-lived network stall, but retrying a payment or other state-changing request can repeat the action.
Do this: First inspect only the response headers and timing from a shell:
curl -sS -D - -o /dev/null \
--connect-timeout 10 --max-time 30 \
-w '\nstatus=%{http_code} connect=%{time_connect}s first_byte=%{time_starttransfer}s total=%{time_total}s\n' \
https://example.com/health
Run it two or three times, with a short pause between attempts. If the request is a GET or HEAD, a limited retry with backoff is usually reasonable. Do not automatically retry a POST or PATCH unless the application documents that the operation is safe to repeat or uses an idempotency key. A 504 does not prove the server did nothing; it may have completed the work after the intermediary stopped waiting.
If the output is not 504, capture the real status. A 403, 429, TLS error, DNS error, or connection refusal is a different problem and should not be forced into the 504 workflow.
Success looks like: You can reproduce the exact status and timing, or you have shown that the error was transient. You also know whether the request was a safe read before trying again.
Step 2: Compare the destination directly and through the proxy
Why: This separates a destination problem from a proxy-path problem. Test the same URL with the same method, headers, and approximate time window.
Do this: Start with a direct request from the client machine:
curl -sS -D - -o /dev/null \
--connect-timeout 10 --max-time 45 \
-w '\ndirect status=%{http_code} remote=%{remote_ip} total=%{time_total}s\n' \
https://example.com/health
Now repeat it through an HTTP proxy. Keep credentials in an environment variable or your shell history protection rather than publishing them:
export PROXY_URL='http://USER:PASSWORD@PROXY_HOST:PROXY_PORT'
curl -sS -D - -o /dev/null \
--proxy "$PROXY_URL" \
--connect-timeout 10 --max-time 45 \
-w '\nproxy status=%{http_code} proxy_connect=%{time_connect}s total=%{time_total}s\n' \
https://example.com/health
For a SOCKS5 proxy, use socks5h:// when you want hostname resolution to happen through the proxy:
curl -sS -D - -o /dev/null \
--proxy 'socks5h://USER:PASSWORD@PROXY_HOST:PROXY_PORT' \
--connect-timeout 10 --max-time 45 \
-w '\nsocks status=%{http_code} total=%{time_total}s\n' \
https://example.com/health
Interpret the results as a matrix:
| Direct result | Proxy result | Likely scope |
|---|---|---|
| 200 | 504 | Proxy route, proxy endpoint, 4G path, or destination behavior for that source IP |
| 504 | 504 | Destination or a shared upstream; confirm from another network and check who generated each response |
| 200 | Connection error | Proxy host, port, authentication, firewall, or proxy service |
| 200 | 200 | The issue may be intermittent, path-specific, or tied to the original URL and request headers |
Compare response headers too. A Server, Via, Proxy-Status, request ID, or branded error page can show which intermediary created the response. RFC 9209 defines the optional Proxy-Status field and error details such as connection_timeout and connection_read_timeout; many deployments do not send it, so its absence is not proof that no proxy was involved.
Success looks like: You know whether the direct path works and whether the proxy path alone fails. You have preserved the headers and timings needed to identify the responding layer.
Step 3: Test the mobile proxy path from the box
Why: A 4G route can fail after the public proxy endpoint accepts your request. Testing from the Raspberry Pi or Linux box shows whether the box can reach the destination over its current outbound path.
Do this: Run the same small health request from the box that owns the dongle route:
curl -sS -D - -o /dev/null \
--connect-timeout 10 --max-time 45 \
-w '\nbox status=%{http_code} remote=%{remote_ip} total=%{time_total}s\n' \
https://example.com/health
Then check the basic network state without exposing SIM or account details:
ip route
getent hosts example.com
curl -sS https://ifconfig.me
Use the public-address result only for comparison with the address you expect from that dongle. Do not treat a changed address as proof that the route is healthy: the destination still needs to respond within the timeout.
If the box request fails while a direct request from another network works, inspect the dongle connection, signal readings, data-plan status, USB power, and DNS. A 4G dongle that keeps disconnecting or an overloaded unpowered hub can interrupt the route long enough for an upstream timeout. If the box succeeds but the public proxy request fails, inspect the proxy service mapping, authentication, port, and cloud-to-box connection instead.
A managed mobile-proxy controller can reduce the amount of custom port-forwarding and firmware scripting in this path. ProxyKite runs on a Raspberry Pi or Linux box with Huawei E3372 HiLink as the reference hardware, exposes HTTP and SOCKS5 endpoints, and works without a static IP or inbound port forwarding. The licence is $9 per dongle per month, with no per-GB charge; it uses the data plan on your own SIM.
Success looks like: The box can make a small request over the intended 4G route, and you can tell whether the failure is before the box, at the box, or after the box.
Step 4: Fix the server or reverse-proxy side
Why: If the destination owner sees 504s for direct requests too, changing the visitor’s browser or proxy will not repair the slow upstream. Find the exact upstream operation that exceeds a configured limit.
Do this: Check logs for the same timestamp across every layer:
- Reverse proxy or load balancer access and error logs.
- Web-server access and upstream timing logs.
- Application logs, worker queues, and dependency calls.
- Database slow-query logs, connection-pool metrics, and lock waits.
- DNS resolver, TLS, firewall, and outbound connection errors.
For NGINX, look at the configured proxy_connect_timeout, proxy_read_timeout, and upstream timing variables. proxy_read_timeout is about the interval between reads from the upstream, not a promise that an entire page may take any length of time. The NGINX proxy module documentation also explains when proxy_next_upstream may pass a request to another server.
Fix the slow operation before raising a timeout. Common repairs include adding a missing database index, reducing an unnecessarily large response, fixing a stalled dependency, increasing healthy application workers, correcting upstream DNS, or removing a connection-pool bottleneck. If the application genuinely needs longer, raise the relevant timeout in a controlled change and keep the outer proxy, load balancer, and client timeouts consistent.
Be careful with automatic upstream retries. NGINX documents that non-idempotent requests are not normally sent to another upstream after the request has been sent, because repeating them can create a second side effect. Keep that protection unless the application has an explicit idempotency design.
Success looks like: The logs show the same request reaching the intended upstream, the upstream finishes within the configured budget, and the 504 rate falls without simply hiding a slow dependency behind a larger number.
Step 5: Fix a proxy or 4G route that times out
Why: When direct traffic works but only one mobile route returns 504, focus on that route’s health and destination reachability instead of changing the website’s application timeout.
Do this: Work through these checks in order:
- Confirm the proxy host and port from the panel or export. A stale port can look like a route failure.
- Confirm authentication separately from destination access. First request a small known URL; then test the target URL.
- Check whether DNS resolution is happening on the client, proxy router, or 4G box. With SOCKS5,
socks5h://keeps hostname resolution on the proxy side. - Check the dongle’s signal and registration state. A weak or changing radio link can delay connection setup and response reads.
- Check USB power and hub stability. If several dongles share a hub, watch for resets and correlate them with 504 timestamps.
- Test another destination. One website timing out points toward destination-specific behavior; several destinations timing out points toward the route or modem.
- Rotate to another healthy route only for a safe read, then compare the result. Do not use rotation as a way to repeat an order, form submission, or other state-changing request.
Keep a short record for each test: route identifier, destination, status, total time, and whether direct access worked. A 4G proxy speed test can help separate latency and throughput from complete reachability. For ongoing fleets, Telegram and webhook alerts for 4G dongles make repeated route failures easier to correlate.
ProxyKite supports on-demand, link-based, and timer-based rotation, plus sticky sessions. It also provides live traffic insights, limits, and webhooks, so you can monitor a route rather than blindly retrying it. A rotation changes the route; it does not make an unhealthy destination application faster.
Success looks like: The affected route reaches a known-good URL, the target responds through that route, or your logs clearly show that the destination—not the mobile path—is the remaining failure.
502 vs 503 vs 504
These codes point to different failure classes, although real products sometimes use them differently. The definitions below come from RFC 9110:
| Code | Meaning | First question |
|---|---|---|
| 502 Bad Gateway | An intermediary received an invalid response from an upstream server. | Did the next hop return malformed, incomplete, or otherwise invalid data? |
| 503 Service Unavailable | The server is temporarily unable to handle the request, often because of overload or maintenance. | Is the service deliberately unavailable, and is there a Retry-After header? |
| 504 Gateway Timeout | An intermediary did not receive a timely response from an upstream server. | Which hop stopped responding before the timeout budget expired? |
Do not “fix” a 504 by treating every 5xx as retryable. For safe, idempotent reads, use a small number of retries with exponential backoff and jitter. For POST and other state-changing requests, use the application’s idempotency mechanism or ask the API owner before retrying. Also check for a Retry-After header; it is defined for 503, but a service may document its own retry behavior for other responses.
Common mistakes
- Increasing every timeout at once: This turns a clear failure into longer waits and can exhaust workers or connections. Change the timeout at the layer that owns the slow operation.
- Testing a different request: A browser request with cookies and a
POSTis not equivalent to acurlrequest for a publicGET. Match the method, URL, headers, and authentication where possible. - Blaming the origin immediately: If direct access works and only one proxy route fails, inspect that route first.
- Assuming a 504 identifies the creator: Read the response headers and compare logs. A proxy may return a 504 for a timeout it experienced before the destination ever saw the request.
- Retrying side effects: A timeout is ambiguous. The server may have completed the operation even if the client received 504.
- Rotating too aggressively: Frequent route changes can make diagnosis harder and can hide a physical USB, signal, or power problem. Stabilise and measure one route before changing several variables.
FAQ
Is a 504 error code caused by my internet connection?
Usually, a 504 is generated by a server or intermediary waiting for another server. Your local network, VPN, DNS, or proxy can still be the failing hop. Compare the same URL directly, through the proxy, and from another network to locate it.
How do I fix a 504 Gateway Timeout as a visitor?
Retry a safe read once, then test another network and disable a custom VPN or proxy temporarily. Clear only temporary connection state if the browser is affected, and send the site owner the URL, time, status, and response headers. If the site fails for everyone, only its operator can repair the upstream service.
Why do I get 504 only when using a proxy?
The proxy route may be slow, the proxy endpoint may have a stale or unhealthy mapping, or the destination may be delaying that source address. Test the same URL directly and from the proxy’s Linux box, then check the route’s modem, signal, DNS, and logs.
Can changing the proxy IP fix a 504?
It can help when one route or destination path is unhealthy, but it is not a general fix. Change one variable, repeat a safe request, and keep the original status and timing so you can distinguish a route problem from a slow origin.
Should I increase the server timeout for every 504?
No. First identify whether the delay is DNS, connection setup, response reads, application work, or a mobile route. Increase a specific timeout only when the operation is expected to take longer and you have measured the resource cost; otherwise fix the slow upstream.
For a 504 error code, the fastest reliable workflow is simple: capture the response, compare direct and proxied requests, test the box and 4G route, then match timestamps across proxy and application logs. Once you know which hop timed out, the repair is usually specific—and much safer than raising every timeout or retrying every request.