Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk11 min

How to Fix a 504 Gateway Timeout Error on Your Server

A 504 means a gateway or proxy did not receive a timely upstream response. This guide shows how to trace the failing layer, test it from the proxy host, fix NGINX and Apache settings, handle CDN-generated errors, and avoid harmful timeout increases.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A 504 means a gateway or proxy waited for an upstream server and did not receive a response before its deadline. Fix it by identifying which layer returned the error, matching logs at the failure time, testing the upstream from the proxy host, correcting the slow or unreachable component, and only then adjusting timeout budgets. Raising a timeout around an unhealthy backend usually increases queueing rather than solving the incident.

What a 504 Gateway Timeout actually means

HTTP status 504 is generated by a gateway or proxy, not normally by the browser. RFC 9110 defines it this way:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The 504 (Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.”

In a typical request, the layers are client, CDN or load balancer, reverse proxy, application server, database, and possibly an external API. A timeout can occur between any two of those layers. The status alone does not identify the slow component.

#1 Best Overall
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)

504 versus 502

A 504 means the proxy did not receive an HTTP response from the origin or upstream within the allowed time. A 502 generally means the gateway received an invalid response, or could not use the response it received. The distinction matters: a 504 investigation focuses first on elapsed time, queues, blocked workers, and reachability; a 502 investigation focuses more on protocol errors, crashed processes, malformed headers, and connection failures.

MDN notes that 504 failures have many possible causes and usually require investigation by the server administrator; a site may also recover when a temporary overload clears. Treat a 504 as a symptom of a communication or processing deadline, not as a diagnosis.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start with a precise incident record

Before changing configuration, capture one reproducible failure. Record the exact URL and HTTP method, the time in UTC, response headers and body, any request or trace identifier, and whether the problem affects every visitor or only a particular network, region, hostname, or endpoint.

Compare a working request with the failing request

  • Request a simple endpoint such as a health or static route and compare it with the route returning 504.
  • Check whether GET, POST, uploads, streaming responses, or long-running reports fail differently.
  • Test the public hostname and, where safe, the same route through an internal path.
  • Note whether all instances fail or only one backend member.

A single slow endpoint points toward its application code, database query, or dependency. A 504 on every route points toward a shared proxy, network, capacity, or origin failure.

Identify which layer generated the response

Look at the page branding, headers, body format, and request identifiers. A CDN, load balancer, reverse proxy, and origin can each produce a visually different error. Cloudflare documents two broad possibilities: the 502 or 504 was generated by the origin, or it was generated by Cloudflare while attempting to reach the origin.

Do not assume that a branded edge page proves the application is healthy or unhealthy. Confirm the source in logs and provider diagnostics. If the response is unbranded, inspect the reverse-proxy and origin logs first; if it carries an edge request or Ray identifier, preserve that identifier for correlation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Correlate logs at the same UTC timestamp

Use the captured time, hostname, route, and request ID to follow one request through every layer. A log entry that is several minutes away is not a useful match during a busy incident.

Layer Inspect Useful clues
CDN or edge Request status, origin status, edge timing, provider request or Ray ID Edge could not connect, edge waited for origin, or origin returned the error
Load balancer Target health, connect time, response time, retries, pool membership One unhealthy target, repeated retries, or a pool with no available workers
NGINX or Apache Error and access logs, upstream address, phase, elapsed time “upstream timed out” and whether the timeout occurred while connecting, sending, or reading
Application Request start and finish, queue time, worker state, exceptions, deploy markers Blocked threads, long handlers, restarts, or a request that never completed
Database or dependency Query duration, connection pool, locks, errors, saturation Slow queries, exhausted pools, lock waits, or an unavailable external service

In NGINX, the wording “upstream timed out” confirms a timeout while communicating with the upstream. The phase is essential: connect, send, and read failures have different remedies.

Rank #2
Sale
UGREEN NAS DH2300 2-Bay for Beginners & Personal Users, Phone Backup | AI Album, Private Cloud/Remote Access, File Sharing, Multi-Device Backup, Home Entertainment, 4GB RAM on Board (Diskless)
  • Entry-level NAS Personal Storage:UGREEN NAS DH2300 is your first and best NAS made easy. It is designed for beginners who want a simple, private way to store videos, photos and personal files, which is intuitive for users moving from cloud storage or external drives and move away from scattered date across devices. This entry-level NAS 2-bay perfect for personal entertainment, photo storage, and easy data backup (doesn't support Docker or virtual machines).
  • Set Your Devices Free, Expand Your Digital World: This unified storage hub supports massive capacity up to 64TB.*Storage drives not included. Stop Deleting, Start Storing. You can store 22 million 3MB images, or 2 million 30MB songs, or 43K 1.5GB movies or 67 million 1MB documents! UGREEN NAS is a better way to free up storage across all your devices such as phones, computers, tablets and also does automatic backups across devices regardless of the operating system—Window, iOS, Android or macOS.
  • The Smarter Long-term Way to Store: Unlike cloud storage with recurring monthly fees, a UGREEN NAS enclosure requires only a one-time purchase for long-term use. For example, you only need to pay $459.98 for a NAS, while for cloud storage, you need to pay $719.88 per year, $2,159.64 for 3 years, $3,599.40 for 5 years. You will save $6,738.82 over 10 years with UGREEN NAS! *NAS cost based on DH2300 + 12TB HDD; cloud cost based on 12TB plan (e.g. $59.99/month).
  • Blazing Speed, Minimal Power: Equipped with a high-performance processor, 1GbE port, and 4GB RAM on Board, this NAS handles multiple tasks with ease. File transfers reach up to 125MB/s—a 1GB file takes only 8 seconds. Don't let slow clouds hold you back; they often need over 100 seconds for the same task. The difference is clear.
  • Let AI Better Organize Your Memories: UGREEN NAS uses AI to tag faces, locations, texts, and objects—so you can effortlessly find any photo by searching for who or what's in it in seconds. It also automatically finds and deletes similar or duplicate photo, backs up live photos and allows you to share them with your friends or family with just one tap. Everything stays effortlessly organized, powered by intelligent tagging and recognition.

Test the upstream from the proxy host

A request from your laptop tests the public path; it does not prove that the reverse proxy can reach its configured upstream. Run an authenticated-safe request from the proxy host or the same network segment, using the hostname, port, protocol, path, and headers that the proxy actually uses.

curl -v --connect-timeout 5 --max-time 30 http://upstream.example/health

Use a health endpoint that does not mutate data. If authentication, a specific Host header, SNI name, or client certificate is required, reproduce those requirements without exposing credentials in shell history or support tickets.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Interpret the result

  • Connection fails or times out: investigate DNS, routing, firewall rules, security groups, listener state, TLS, and backend health.
  • Connection succeeds but the route is slow: investigate application queues, database calls, locks, and external services used by that route.
  • Direct request is fast but public requests time out: examine proxy configuration, connection pools, retries, edge behavior, request headers, and capacity under real concurrency.
  • Health endpoint is fast but the business route is slow: the process is reachable; focus on the route’s work rather than merely increasing a global timeout.

Check health, capacity, and recent changes

At the failure time, check resource graphs and service events rather than relying on a current snapshot. Look for:

  • CPU or memory exhaustion and out-of-memory kills
  • Worker, process, file-descriptor, or connection limits
  • Database connection-pool saturation, lock waits, and slow queries
  • Blocked application threads, growing queues, or exhausted event loops
  • Container or instance restarts and failed health checks
  • Network packet loss, retransmissions, or a listener that stopped accepting connections
  • A deployment, configuration change, certificate change, DNS change, or firewall change immediately before the incident

Cloudflare’s support guidance lists excessive origin load, crashes, network failures, and applications or services that timed out among the origin-side causes to investigate. Restore a crashed dependency, roll back a harmful deployment, add capacity, or remove the blocking condition before changing proxy deadlines.

Verify the network path and protocol

When a proxy cannot reach an origin, verify each property independently:

  1. Resolve the backend hostname from the proxy host and confirm that the address is the intended one.
  2. Confirm that the route and port are reachable from the proxy network, not just from an administrator workstation.
  3. Check security-group, firewall, and network-policy rules in both directions.
  4. For HTTPS upstreams, verify certificate validity, the expected SNI name, and the protocol and cipher settings accepted by the backend.
  5. Confirm that the origin accepts connections from the CDN or load balancer source addresses.
  6. Check that the proxy uses the correct Host header, path prefix, and URL scheme.

A DNS record can be correct for public visitors and still be wrong from an internal resolver. Likewise, a firewall can allow an administrator’s address while silently dropping the proxy or edge provider’s addresses.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Fix the component that exceeded its deadline

Connection-establishment timeout

If the proxy cannot establish a TCP or TLS connection, fix listener availability, routing, DNS, firewall policy, TLS/SNI configuration, or backend capacity. Adding response time will not help a connection that never forms.

Request-send timeout

A send timeout indicates that the proxy could not transmit the request to the upstream in time. Investigate a stalled network path, a backend that is no longer reading, oversized uploads, flow-control problems, or a saturated connection pool. For uploads, make sure the proxy’s request-body limits and buffering behavior match the application’s design.

Rank #3
Sale
UGREEN NAS DXP2800 2-Bay for Advanced Home Users, Remote Workers & Creators | Home Media & Data Center, Docker & VM, Plex, Fast File Transfer, Intel N100, 8GB DDR5, 2.5GbE, 2x M.2 NVMe, 4K HDMI(Diskless)
  • 【Advanced Home Data & Media Hub】For advanced home users who need phone backup, file storage, and centralized data management. Centralize family photos, 4K videos, movies, computer backups, and personal files in one place while running multiple apps for home entertainment and everyday data management. Suitable for households with growing digital libraries and multiple NAS use cases.
  • 【Built for Creators, Media Servers & Advanced Apps】Powered by the Intel N100 Quad-Core CPU, 8GB DDR5 RAM, 2.5GbE networking, and dual M.2 NVMe slots, DXP2800 handles large files and heavier workloads with ease. Run Docker, virtual machines, and media server applications compatible with Plex—ideal for content creators, tech enthusiasts, and advanced home users managing 4K videos, RAW photos, personal media libraries, and multiple NAS apps.
  • 【Up to 80TB for Growing Digital Libraries】 Supports up to 80TB of storage using two HDD bays and two M.2 NVMe SSD slots for family photos, movies, RAW photos, 4K videos, work files, and device backups. AI photo management supports recognition of people, objects, scenes, and locations, album organization, and duplicate photo detection. HDDs and SSDs are not included.
  • 【AI-powered Home Surveillance】Turn DXP2800 into a centralized home surveillance hub by connecting compatible network cameras and storing recordings locally on your NAS. AI-powered features include Face Recognition, People Detection, and Pet Detection, helping advanced home users review important events more efficiently while managing home surveillance and personal data in one place.
  • 【One data Center Across Your Devices】Keep files from desktops, laptops, phones, tablets, and other devices together instead of scattered across cloud accounts and external drives. Access, back up, organize, and share data across Windows, macOS, Android, iOS, web browsers, and compatible smart TVs—ideal for creators and advanced home users working across multiple devices.

Response-read timeout

A read timeout means the upstream connection exists but the proxy did not receive the expected response data before the read budget expired. Profile the endpoint, database calls, locks, templates, and external APIs. If the operation is legitimately long-running, return a job identifier and process it asynchronously instead of holding a browser request and a worker open.

Dependency timeout

An application can be healthy while one database, queue, or external API is slow. Set bounded client timeouts, use retries only where they are safe, and provide fallback or queued processing. Unbounded retries can multiply traffic and turn one dependency failure into a full-origin outage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Align timeout budgets only after the upstream is healthy

Every hop needs a deliberate budget. The outer hop must allow enough time for the inner operation to complete, but not so much that failed requests occupy all workers and connections. Include network overhead, queue time, application work, and any retry policy in the budget.

Question Decision to make Why it matters
Which phase failed? Connect, send, read, or dependency Each phase has a different corrective action
Which layer failed? Edge, load balancer, proxy, application, database, or external API A setting at the wrong layer cannot repair the failing component
What is the latency budget? Expected service time plus queue and network allowance A larger budget can increase concurrency and queueing pressure
What is the blast radius? One route, one upstream pool, one region, or the entire service Scope the change so an experiment does not affect unrelated traffic

Do not raise every timeout indiscriminately. A longer deadline is appropriate only when the endpoint is expected to take that long and the backend has enough concurrency, memory, database capacity, and connection slots to sustain it.

Fixing 504 errors in NGINX

NGINX’s proxy module separates connection establishment, sending the request, and reading the response.

Directive Controls Documented example value
proxy_connect_timeout Time allowed to establish a connection to the proxied server 5s
proxy_send_timeout Time allowed while sending the request to the proxied server 30s
proxy_read_timeout Time allowed while reading a response from the proxied server 60s

proxy_connect_timeout defaults to 60s and usually cannot exceed 75 seconds in practice. The example values below are a pattern, not universal answers; select them from measured service behavior and your capacity budget.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
location /api/ {
    proxy_pass http://app_backend;
    proxy_connect_timeout 5s;
    proxy_send_timeout 30s;
    proxy_read_timeout 60s;
}

Apply an NGINX change safely

  1. Confirm that the request matches the intended server and location block. A correct directive in an unused block changes nothing.
  2. Inspect the complete effective configuration with nginx -T when you need to verify includes, inheritance, and duplicate locations.
  3. Validate syntax with nginx -t. Do not reload a configuration that fails validation.
  4. Reload gracefully using your operating system’s service procedure, preserving existing connections where supported.
  5. Repeat the controlled request and check both NGINX and application logs to confirm that the new block handled it.

If the upstream remains slow, revert the timeout experiment and fix the endpoint, dependency, or capacity problem instead of continuing to increase the number.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Fixing 504 errors in Apache HTTP Server

Apache mod_proxy provides ProxyTimeout, the network timeout for proxied requests. Its default is the global Timeout value. Individual ProxyPass workers can set connection and request timeouts independently.

Rank #4
Dell PowerEdge R730xd Server 24B SFF 2U, 2X Intel Xeon E5-2690 v4 2.6Ghz (28-cores Total), 128GB DDR4 RAM, 4X 1.2TB 10K SAS 2.5” 12Gb/s HDD, H730P 2GB RAID, NIC 10Gb + I350 1Gb (Renewed)
  • Dell PowerEdge R730xd 24B SFF 2U Server
  • 2x Intel Xeon E5-2690 v4 2.6Ghz 14-Core (28-cores Total)
  • 128GB DDR4 RAM – 4x 1.2TB 10K SAS 2.5” 12Gb/s
  • Dell H730P mini 2GB 12Gb/s RAID
  • 2x 750W PSU - 2x 10Gb SFP+ 2x 1Gb (RJ45) NIC
ProxyPass        "/api" "http://backend.example.com/api" connectiontimeout=5 timeout=60
ProxyPassReverse "/api" "http://backend.example.com/api"
# Or set a proxy-wide budget when appropriate:
# ProxyTimeout 60

Apache documentation also shows the form ProxyPass "/example" "http://backend.example.com" connectiontimeout=5 timeout=30. These numbers illustrate syntax; choose values from the endpoint’s measured behavior and available concurrency.

Apply an Apache change safely

  1. Place the directive in the virtual host or proxy context that serves the failing hostname and path.
  2. Check the complete loaded configuration with the server’s configuration-test command for your installation.
  3. Reload gracefully according to your platform’s service procedure.
  4. Verify backend access logs, application logs, and the public response after the reload.

A longer ProxyTimeout is justified only for an operation expected to run that long. If workers, database connections, or upstream sockets are already saturated, the longer wait can make the outage larger.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When a CDN or Cloudflare is in front of the server

First determine whether the edge returned the 504 or passed through a response produced by your origin. Check the page style, headers, edge diagnostics, origin status, and request or Ray ID. Then compare the edge timestamp with the origin and reverse-proxy logs.

If the origin generated the response, follow the normal upstream workflow: confirm that it answers for the requested hostname, inspect load and crashes, verify network access, and find the application or service that timed out. If the edge could not reach the origin, verify DNS from the provider’s perspective, allow the provider’s source addresses, confirm the listening port and TLS configuration, and check regional or route-specific failures.

When you cannot access the origin or provider diagnostics, give the hosting or CDN provider a UTC timestamp, hostname, sanitized curl reproduction, affected path, and the edge request or Ray ID. Do not send credentials or private tokens.

Retest through the complete public path

After fixing the root cause or applying a narrowly scoped timeout change, reproduce the request through the same hostname and method that failed. Confirm an expected 2xx or application response, not merely the disappearance of the 504 page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Run the request several times to detect intermittent failures.
  • Test the previously working endpoint and the previously failing endpoint.
  • Check more than one backend instance or region when traffic is distributed.
  • Watch timeout rate, latency percentiles, queue depth, CPU and memory saturation, connection pools, restarts, and error logs during normal traffic.
  • Keep the configuration change documented so it can be correlated with later incidents.

Common fixes that do not solve the problem

  • Refreshing the browser repeatedly: this can add load while leaving the upstream failure untouched.
  • Increasing every timeout: it hides the failing phase and allows more requests to occupy scarce workers.
  • Testing only from outside the network: a public success does not prove that the proxy host can reach its configured backend.
  • Checking only the proxy log: the application, database, or external dependency may contain the actual slow operation.
  • Assuming the edge is at fault: many 504 pages are generated by an origin or reverse proxy behind the edge.
  • Ignoring deploys and capacity: a new query, worker limit, certificate, DNS record, or firewall rule can create a timeout without any code crash.

A compact decision path

  1. Capture the failing URL, method, UTC time, headers, body, and request identifiers.
  2. Identify whether the response came from the CDN, load balancer, reverse proxy, or origin.
  3. Correlate logs across that layer, the application, and its dependencies.
  4. Test the exact upstream path from the proxy host with a safe curl request.
  5. Classify the failure as connect, send, read, or dependency timeout.
  6. Repair reachability, crashes, slow code, blocked queries, exhausted pools, or insufficient capacity.
  7. Align only the necessary timeout budget after the upstream is healthy.
  8. Validate configuration, reload safely, retest publicly, and monitor saturation and timeout rates.

The practical goal is not merely to make the 504 page disappear. It is to make each layer fail predictably, preserve capacity during slowdowns, and give operators enough timing and identifiers to locate the next bottleneck quickly.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.