Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Fix a 504 Gateway Timeout Error in Nginx

A 504 from NGINX means an upstream response did not arrive in time. This guide shows how to identify the timeout phase, test the backend from the NGINX host, fix application and network causes, and change proxy timeouts without masking failures.
WorldNginx Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A 504 Gateway Timeout means NGINX, acting as a proxy, did not receive a timely response from its upstream service. The upstream might be an application server, FastCGI or PHP service, database-backed endpoint, container, load balancer, or another proxy. Start by identifying whether NGINX timed out while connecting, waiting for response headers, or waiting between response reads. Then fix the slow or unreachable component; increase a timeout only when measurements show that the request legitimately needs more time.

What a 504 Gateway Timeout means

MDN defines HTTP 504 as the response returned when a server acting as a gateway or proxy does not get a response from an upstream server in time to complete the request. In an NGINX deployment, “upstream” is the service named by proxy_pass or a related pass directive. It may be a web application, PHP-FPM process, Gunicorn or Node worker, database-backed API, container service, internal load balancer, or another proxy hop.

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 status identifies a timeout relationship, not the component at fault. NGINX may be healthy while the application is blocked on a slow query. A backend may be healthy while a firewall, security group, route, service-discovery record, TLS handshake, or load-balancer health check prevents NGINX from reaching it. An outer CDN or load balancer can also generate its own 504 before NGINX’s limits are reached.

  • Connection timeout: NGINX cannot establish the upstream connection within the configured interval.
  • Response-read timeout: NGINX connected, but the upstream did not provide response data within the allowed gap between reads.
  • Send timeout: NGINX cannot send the request to the upstream because the receiving side is not accepting data quickly enough.

These are interval controls. In particular, proxy_read_timeout is not a stopwatch for the entire response. It applies only between two successive read operations. A streaming response that sends a chunk before each interval expires can therefore remain active longer than the configured number, while a silent upstream can time out even when its eventual total response would have been acceptable.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Why NGINX often returns a 504 after 60 seconds

The NGINX proxy module documents a default of 60 seconds for both proxy_connect_timeout and proxy_read_timeout. A request that fails close to one of those boundaries is a useful clue, not proof that the application always needs exactly one minute.

Directive Documented default What the interval measures
proxy_connect_timeout 60 seconds Time allowed to establish a connection to the proxied server.
proxy_read_timeout 60 seconds Maximum idle interval between two successive reads from the proxied server, not the total response duration.

The effective limit can also come from a more specific location, a parent server or http block, an NGINX distribution or version, an NGINX Gateway Fabric policy, or another proxy in front of NGINX. Check every hop before assuming that changing one directive will change the client-visible timeout.

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

Diagnose the timeout before changing configuration

Use the same failing URL and capture the time of each test. A consistent delay near 60 seconds points toward a configured interval; variable delays suggest queueing, intermittent reachability, or changing backend load.

1. Reproduce and classify the delay

  1. Request the exact path, method, and representative parameters that produce the 504.
  2. Record whether the request fails immediately, after a repeatable interval, or only under load.
  3. Note whether other routes using the same upstream succeed. A single slow endpoint often indicates application or database work, while every route failing suggests connectivity, readiness, or capacity trouble.

Do not infer the phase from elapsed time alone. The error log contains the decisive wording and usually includes the upstream address and request context.

2. Read the NGINX error log at the incident time

Open the error log entries generated for the failed request and preserve the complete message. Determine whether it reports a connection attempt, a failure while reading the upstream response, or a send operation. Keep the upstream address and request path with the record; those details distinguish one unhealthy peer or route from a global problem.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

A connection-related message sends the investigation toward DNS, routing, firewall rules, security groups, TLS negotiation, service discovery, or a backend that is not listening. A read-related message means NGINX connected but then waited for response data. That commonly leads to application queues, worker starvation, deadlocks, slow queries, or a downstream API call. A send-related message points to backpressure while NGINX is forwarding the request.

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

3. Add upstream timing to access logs

NGINX logging guidance supports recording timing values for the upstream connection and for receiving the response. Configure or inspect an access-log format that exposes those upstream timing fields, then compare successful and failed requests. The useful pattern is:

  • A high connection time with little or no response time indicates reachability or connection-establishment trouble.
  • A short connection time followed by a long wait for the first response data indicates backend processing or queueing.
  • Short initial response time followed by long gaps between reads indicates an idle streaming or chunked response, or a backend that pauses while doing additional work.

Keep the timing data for the same route and upstream peer. Averages can hide a tail-latency problem that affects only a subset of requests.

4. Call the upstream directly from the NGINX host

From the machine, container, or pod that runs NGINX, make an equivalent request to the upstream address. Use the same path, method, headers, authentication context, and payload where practical. Compare:

  • DNS resolution and the address selected;
  • TCP connection establishment;
  • TLS handshake time when HTTPS is used between NGINX and the upstream;
  • time to first byte; and
  • total completion time.

If the direct request is already slow or cannot connect, changing NGINX’s read timeout only hides the symptom. If the direct request is fast but the proxied request is slow, inspect NGINX routing, proxy settings, name resolution from the NGINX runtime, connection reuse, request headers, and every intermediary between the two services.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)

5. Check application and host saturation

At the same timestamps, inspect the application, database, PHP-FPM, Gunicorn, Node, container, and host metrics. Look for exhausted workers, a growing request queue, CPU or memory pressure, blocked I/O, deadlocks, connection-pool exhaustion, and slow database queries. A backend can accept a TCP connection while having no available worker to produce a response, which appears to NGINX as a read timeout.

Trace the endpoint’s downstream calls. A request that waits on another API, a database lock, or a background job can exceed the proxy budget even when the front-end process itself is functioning normally.

6. Check intermittent network and routing failures

For failures that affect only some requests, compare the upstream peer selected for successful and failed calls. Verify service-discovery records, routes, firewall policies, security groups, network policies, TLS certificates and protocol settings, and load-balancer health. In an upstream group, one unavailable or overloaded peer can create a pattern that looks random until the peer identity is logged.

Fix the underlying cause

The durable fix depends on the timeout phase. Treat a larger timeout as a deliberate service-level decision, not as the default remedy.

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

When the upstream connection cannot be established

  • Correct an incorrect hostname, address, port, or service-discovery record.
  • Restore the route between NGINX and the upstream network.
  • Allow the connection through host firewalls, security groups, and network policies.
  • Fix TLS configuration when the upstream requires HTTPS, including protocol and certificate expectations.
  • Make sure the service is listening and marked ready before traffic is sent to it.
  • Remove or replace an unhealthy peer in an upstream group and verify load-balancer health checks.

Do not raise proxy_connect_timeout to compensate for a blocked port or a missing route. A longer wait makes each failed request consume resources for longer and delays detection of an unavailable service.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

When the application is slow to produce headers

  • Optimize the endpoint’s database query and remove avoidable downstream calls.
  • Resolve lock contention, deadlocks, and exhausted database or HTTP connection pools.
  • Increase application-worker capacity when queue depth and worker utilization show saturation.
  • Move work that does not belong on the synchronous request path into a background job, returning a status that the client can poll when appropriate.
  • Cache safe, repeatable results and avoid doing the same expensive calculation for every request.

Measure the endpoint’s normal and tail duration after each change. The goal is to make the backend respond within the user-facing budget, not merely to make NGINX wait longer.

When there are idle gaps between response reads

First determine whether the endpoint is intentionally streaming. If it is, the read timeout must exceed the longest expected silent interval, and the application must emit data often enough to keep the connection meaningful. If streaming is not intentional, investigate pauses caused by database work, downstream calls, buffering, worker starvation, or a stalled process.

Because proxy_read_timeout measures the gap between reads, a value that appears large enough for the total request can still fail when the application stops sending data temporarily. Conversely, an extremely large value can leave clients and NGINX workers occupied while a broken request remains queued.

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

When an upstream group is overloaded

Review peer health, queue depth, balancing behavior, and capacity. NGINX upstream groups support load balancing for proxy and related pass directives, while upstream queue limits and queue timeouts determine what happens when peers are unavailable or busy. Queue exhaustion requires more capacity, corrected health checks, or routing changes; increasing only proxy_read_timeout does not create workers or healthy peers.

When increasing NGINX timeouts is appropriate

Increase a timeout only after direct testing and logs show that the request is healthy but legitimately longer than the current interval. Examples include a report-generation route with a measured processing time, or a streaming endpoint whose longest expected idle gap is known. Set the value for that route rather than globally whenever possible.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

Choose the value using the endpoint’s tail latency, backend capacity, and user tolerance. Include headroom for normal variation, but keep a finite upper bound so that a failed backend cannot hold connections indefinitely. Coordinate the budget across every proxy hop: an outer load balancer that expires first will still return its own 504 even if NGINX allows a longer wait.

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

Example proxy configuration

The following example uses values from the NGINX timeout guidance. They are starting points for a measured service-level objective, not universal recommendations:

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.
location / {
    proxy_pass http://backend;
    proxy_connect_timeout 10s;
    proxy_read_timeout 120s;
    proxy_send_timeout 30s;
}

Place directives in the correct http, server, or location block. A route-specific block is safer when only one endpoint needs a longer budget. Confirm that the request actually matches that block; an apparently correct setting has no effect if another, more specific location handles the URL.

Validate and reload safely

  1. Save the configuration in the file included by the active NGINX process.
  2. Run nginx -t. Do not reload if the syntax or referenced configuration is invalid.
  3. Reload NGINX through the service manager used by the host.
  4. Repeat the original request and record the new elapsed time.
  5. Inspect error and access logs to confirm the request used the intended block and upstream.
  6. Verify that the backend completes within the chosen budget and that connection, worker, and queue usage remain healthy.

A reload changes NGINX’s configuration but cannot repair a slow application, unavailable peer, or blocked network path. If the 504 remains, return to the timeout phase identified in the logs rather than raising the value again.

Compare possible fixes using five questions

When several changes appear plausible, evaluate each against the same criteria:

Question Why it matters
Is the delay during connection, header generation, or an idle response gap? Each phase has a different cause and may require a different directive or backend fix.
What are normal and tail request durations? A timeout should cover legitimate tail latency without allowing indefinite hangs.
How much backend capacity and queue depth are available? A longer proxy interval cannot solve worker starvation or an overloaded upstream group.
How long will users accept waiting? The technically possible wait may still be unacceptable for an interactive request.
Should the change apply to one route or globally? The narrowest scope limits collateral effects on unrelated traffic.

Common mistakes that make 504s worse

  • Changing only proxy_read_timeout: A connection timeout, send timeout, firewall block, or outer proxy limit will remain unchanged.
  • Assuming 60 seconds proves an application bug: It may be the documented default, but a proxy, distribution, or deployment layer can impose another limit.
  • Using a huge global timeout: Broken requests retain client and worker resources, and queues can grow until a larger outage results.
  • Testing from the wrong network location: A laptop may resolve or reach a service differently from the NGINX host, container, or pod.
  • Ignoring intermittent peers: Aggregate latency can look acceptable while one unhealthy upstream repeatedly causes failures.
  • Skipping configuration validation: Reloading without nginx -t risks leaving the service on an old configuration or introducing a reload failure.
  • Focusing only on NGINX: Database locks, application queues, downstream APIs, readiness failures, and network policy are frequent causes of the wait.

Deployment-specific limits to check

Open-source NGINX directives and defaults can vary by NGINX version, distribution, enabled module, and deployment layer. Kubernetes Gateway API or NGINX Gateway Fabric may expose timeout policy through resources rather than a traditional NGINX server block. In those environments, identify the policy object that owns the route and verify the generated configuration or status.

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

Also map every proxy hop. A CDN, ingress controller, cloud load balancer, service mesh, or internal gateway may have an independent connect or response limit. The hop that sends the 504 is the one whose logs identify its immediate upstream; tracing the request across all hops prevents a local NGINX change from masking the actual limit.

A practical decision path

  1. Find the exact failing hop: Match the client timestamp to NGINX and any outer-proxy logs.
  2. Read the NGINX error message: Classify the event as connect, read, or send timeout.
  3. Test from NGINX to the upstream: Compare resolution, connection, TLS, first byte, and completion.
  4. Inspect capacity and dependencies: Check workers, queues, databases, downstream calls, containers, and host resources.
  5. Repair the cause: Fix routing, policy, readiness, capacity, query performance, or endpoint design.
  6. Adjust the narrowest timeout only if justified: Use measured tail latency and the user-facing budget.
  7. Validate, reload, and observe: Run nginx -t, reload through the host’s service manager, repeat the request, and verify logs and resource behavior.

What a successful fix looks like

The request completes within the intended service-level objective, not merely before an arbitrarily larger timeout. NGINX logs show the expected upstream and timing phase, direct upstream tests remain healthy, worker and queue metrics stay within capacity, and no outer proxy expires first. Keep the measured timeout rationale with the configuration so a future change does not turn a one-route exception into a global 504 problem.

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 quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

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.