DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
VGSources
Blog

How to Find the Cause of a 504 Gateway Timeout on NGINX

A 504 is an upstream communication timeout, not automatically a slow application. Learn how to use NGINX error logs, upstream timing variables, direct curl tests, and timeout budgets to find the failing phase and fix the underlying cause.
Length11 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A 504 from NGINX means the gateway did not complete communication with its upstream within the applicable timeout window. The fastest diagnosis is to identify which phase failed: connecting to the upstream, waiting for its response headers, or waiting between response reads. Start with the error log, add upstream timing fields to the access log, and test the backend directly from the NGINX host before changing any timeout.

What an NGINX 504 actually tells you

NGINX sits between the client and an upstream application server. When NGINX returns 504 Gateway Timeout, it is reporting a failure to complete that upstream exchange in time. The status alone does not tell you whether the backend is down, overloaded, unreachable, slow to begin responding, or merely silent for too long during an otherwise valid response.

As an Amazon Associate I earn from qualifying purchases.

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.

Separate the request into three timing phases:

  • Connection establishment: NGINX cannot establish or complete a connection to the configured upstream.
  • Response-header wait: NGINX connects, but the upstream does not send the first response-header byte soon enough.
  • Response-read gap: The upstream began responding, then exceeded the allowed interval between read operations.

Those phases lead to different fixes. A larger read timeout cannot repair a blocked route, a closed port, an exhausted application worker pool, or a failed database. It only allows NGINX to wait longer when the upstream is healthy and intentionally quiet.

Use this diagnostic sequence

  1. Record the exact failing request and its timing.
  2. Read the NGINX error log for the same request.
  3. Add upstream timing variables to the access log if they are not already present.
  4. Classify the failure as connect, header wait, or response-read gap.
  5. Call the upstream directly from the NGINX host, preserving the original request context.
  6. Compare every timeout along the path before changing a value.
  7. Change proxy_read_timeout only when the evidence supports an idle-read problem.
  8. Escalate briefly to debug logging if normal logs cannot distinguish the failure.
  9. Repeat the request and verify both technical recovery and backend health.

1. Capture the exact request before troubleshooting

Write down enough detail to find one transaction in every system involved. Record the timestamp with timezone, host name, URI, HTTP method, response status, request ID if your application supplies one, and whether the 504 happens on every attempt or only intermittently. Include the request body and relevant authentication or custom headers when the endpoint requires them.

#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.

Consistency is an important clue. A failure that occurs at nearly the same elapsed time on every attempt often indicates a configured timeout boundary. Intermittent failures point more strongly toward capacity, dependency, routing, or network conditions that vary with load. Do not infer the phase from consistency alone; use the logs and timing fields to confirm it.

2. Read the NGINX error log first

The error log records NGINX problems by severity. Its location depends on how NGINX was installed; a common package installation uses /var/log/nginx/error.log. Check the active configuration if your deployment writes to a different file, and search the entries surrounding the recorded timestamp.

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.

Look for wording that identifies the operation NGINX was attempting when the timeout occurred. An entry associated with connecting to an upstream suggests a network or listener problem. An entry that says NGINX timed out while reading from the upstream points toward the response-header or response-body phase. Match the upstream address, port, URI, and request identifier where available so that a busy server’s neighboring requests do not mislead you.

Save the relevant error-log lines rather than relying on a screenshot. You will need to compare them with access-log timings after each change, and the exact timestamp and upstream address can reveal that traffic is being sent to a different backend than expected.

3. Add upstream timing to the access log

Error-log text explains what NGINX reported; timing variables show where the elapsed time accumulated. Configure an access-log format that includes the following NGINX variables alongside the normal request fields:

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
log_format upstream_timing '$remote_addr - $host [$time_local] '
                           '"$request" $status '
                           'upstream_connect=$upstream_connect_time '
                           'upstream_header=$upstream_header_time '
                           'upstream_response=$upstream_response_time '
                           'request_total=$request_time '
                           'request_id=$request_id';

Use that format in the relevant access_log directive, then apply the configuration through your normal controlled deployment process. Confirm that new requests actually produce the four timing fields; an unused format definition does not provide diagnostic data.

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

NGINX defines these values as follows:

Variable What it measures How to use it
$upstream_connect_time Time required to connect to the upstream. High or failed values indicate DNS, routing, firewall, listener, port, or capacity issues.
$upstream_header_time Time until NGINX receives the first response-header byte. A long interval after a normal connection points to application startup, worker exhaustion, locks, slow database work, or another dependency.
$upstream_response_time Time until NGINX receives the last response-body byte. Compare it with header time to find time spent after the response began, including pauses between reads.
$request_time Total request-processing time in NGINX. Shows the end-to-end duration visible at the proxy and helps expose time spent outside the upstream exchange.

The fields are most useful together. A connection that never completes is a different incident from a connection that succeeds quickly but waits for headers for almost the entire timeout window. Likewise, a short header wait followed by a long response time indicates that the application started sending data but later stopped producing it for an excessive interval.

4. Classify the failing phase

Connection establishment is failing

If the connect timing is high, absent, or accompanied by a connect-related timeout, investigate the path between NGINX and the configured upstream. Check name resolution, routing, firewall policy, security groups, the destination port, whether the service is listening, and whether the backend has reached its connection or process capacity. A backend that is completely unreachable cannot be fixed by increasing proxy_read_timeout, because the read phase never begins.

Also verify that the upstream address selected by NGINX is the one you think it is. A stale DNS result, an unhealthy member in a pool, or a port mismatch can make only some requests fail. Compare the address shown in the error log with the configured upstream members and with the address reached by your direct test.

The connection succeeds but headers are late

A normal connection followed by a long header wait means NGINX is connected but the application has not started its response. Common causes include application startup work, an exhausted worker pool, a lock, a slow database query, or another dependency that must finish before the first byte can be generated.

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)

Inspect application and database metrics for the same timestamp. Look for queue depth, worker utilization, blocked requests, dependency latency, and resource saturation. If the endpoint is expected to return quickly, correct that backend condition rather than extending a proxy timeout. A longer wait can increase the number of requests occupying workers and make the original overload worse.

The response starts, then pauses

When header timing is reasonable but the interval between response reads becomes too long, determine whether the endpoint is intentionally streaming or whether it has stalled. Streaming, long polling, report generation, and large responses may legitimately contain idle gaps. An application that should continuously produce data but stops unexpectedly may instead have a blocked dependency or exhausted resource.

Check whether the upstream sends periodic bytes, whether buffering changes the observed behavior, and whether another proxy or load balancer imposes a shorter idle interval. Do not describe a successful first byte as proof that the entire response is healthy; the relevant read timeout applies throughout the exchange.

5. Test the upstream directly from the NGINX host

Run a direct request from the machine, container, or network namespace where NGINX makes the upstream connection. Use curl or an equivalent client against the configured upstream host and port. Reproduce the original method, URI, query string, headers, authentication context, and body wherever they affect application behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl --verbose --request POST 
  --header 'Host: example.internal' 
  --header 'Content-Type: application/json' 
  --data '{"example":"value"}' 
  'http://upstream-host:port/path'

The command above is a pattern, not a universal request. Replace the method, headers, body, scheme, host, port, and path with the values from the failed transaction. Avoid removing authentication or tenant headers merely to make a test easier; doing so can exercise a different code path.

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

Compare direct timing with the proxied request. If the direct call is also slow before headers arrive, the backend or one of its dependencies is the likely cause. If the direct call is fast but the proxied call cannot connect or waits much longer, investigate NGINX routing, name resolution, firewall rules, connection limits, and the network path between the two services. Repeat the test enough times to distinguish a deterministic problem from an intermittent one.

6. Check every timeout in the request path

NGINX has independent connect, read, and send timeout concepts. NGINX Gateway Fabric documentation also describes these as separate controls. Read and send values are intervals between operations, not a single total-transfer limit. The complete request path may include the client, a CDN or load balancer, NGINX, another proxy, the application server, and a database or service dependency.

Question Why it matters
Can NGINX establish the upstream connection within its connect timeout? A short connect limit can fail a congested or distant backend before the application receives the request.
How long may NGINX wait between upstream reads? This governs silence after connection or after a previous response read; it is not a cap on total response length.
How long may NGINX take to send data to the upstream? Slow clients, large request bodies, or backpressure can affect the send interval.
Will an outer proxy or client give up first? Increasing NGINX’s limit is ineffective if another hop has a shorter deadline.
What timeout does the application use for its dependencies? An application can remain connected to NGINX while waiting on a database or service that has its own deadline.

Write the timeout budget for each hop in one place. The useful value is not the largest timeout; it is an ordered set that gives the intended component enough time while still failing predictably. Align the values with the endpoint’s actual behavior and traffic volume.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

7. Decide whether to change proxy_read_timeout

The documented default for proxy_read_timeout is 60 seconds. NGINX’s directive reference states: “The timeout is set only between two successive read operations, not for the transmission of the whole response.” In practical terms, a response can take longer than 60 seconds overall if it continues to deliver data frequently enough; a response can fail in less time if another component imposes a shorter limit.

Increase the directive only when all of the following are true:

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.
  • The upstream connection succeeds.
  • The backend is healthy and has enough capacity.
  • The endpoint is intentionally silent for longer than the current interval, such as a legitimate long-running or streaming operation.
  • Every outer proxy and client timeout is compatible with the proposed value.
  • You have considered the number of concurrent requests that will remain open during the longer wait.

Do not increase it as a first response to a failed connection, a consistently slow application, a locked database, or an overloaded worker pool. In those cases the change only postpones the error and can consume more connections, workers, memory, and upstream capacity.

Make the smallest scoped change that matches the endpoint rather than raising a global value for unrelated traffic. Record the old and new values, the location where the directive applies, and the reason supported by your timing data. Validate the configuration before reloading it through your established change process.

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

8. Escalate temporarily to debug logging

Use debug logging only after normal error and access logs leave the phase unclear. First confirm that the installed binary includes debug support:

nginx -V

Look for --with-debug in the build options. If it is present, set an appropriately scoped error_log at debug level for the affected server, location, or diagnostic window according to your configuration layout. Reproduce one or a small number of requests, collect the records, and restore the previous log level immediately afterward.

Debug logging can slow NGINX and consume disk quickly. Do not leave it enabled during ordinary high-volume traffic. Restrict the capture as much as your deployment permits, monitor available disk space, and preserve the exact time window so the detailed records can be matched with upstream timing and application logs.

9. Verify the fix instead of assuming it worked

  1. Re-run the original request with the same method, URI, headers, authentication context, and body.
  2. Confirm that the response status is now the expected application status rather than merely a different gateway error.
  3. Compare $upstream_connect_time, $upstream_header_time, $upstream_response_time, and $request_time with the failing request.
  4. Check that the corresponding timeout message has disappeared from the error log.
  5. Watch application, database, and dependency metrics for collateral saturation caused by longer-lived requests.
  6. Repeat under the traffic pattern that originally exposed the problem, including intermittent or concurrent requests when applicable.

A successful single curl request is not sufficient evidence if the original failure occurred only under load. The fix is credible when the failing phase no longer appears, the timing fields fit the endpoint’s intended behavior, and backend health remains stable while real traffic continues.

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

Common misdiagnoses and safer alternatives

  • “Every 504 is a slow application.” A failed connect can occur before the application receives anything. Check connect timing and the error log first.
  • “Set every timeout to a very large value.” Independent hop limits still apply, and longer waits can tie up scarce capacity. Build an end-to-end budget instead.
  • “A first byte means the response is safe.” The read timeout applies between successive reads, so a later idle gap can still produce a 504.
  • “The default of 60 seconds limits total response length.” It limits the interval between reads for proxy_read_timeout, not the total transmission time.
  • “Debug logging should stay on until the issue never returns.” Debug output has operational cost. Capture targeted evidence, then turn it off.
  • “A direct test proves the proxy is configured correctly.” A direct request bypasses NGINX routing and policy. Use it as a comparison, not as a substitute for reviewing the proxied path.

A compact decision framework

Observed evidence Most useful next action Change to avoid as a first step
Connect cannot complete or is consistently slow. Check DNS, route, firewall, listener, port, upstream membership, and backend connection capacity. Increasing proxy_read_timeout.
Connects normally; first response header is late. Inspect application workers, startup work, locks, database calls, and other dependencies. Masking the backend delay with a much larger global timeout.
Headers arrive; later reads pause beyond the interval. Determine whether the endpoint intentionally streams or has stalled, then align read limits across hops. Assuming total response size is the problem.
Normal logs cannot identify the operation. Use a short, scoped debug-log capture when nginx -V shows --with-debug. Leaving debug logging enabled indefinitely.

What to retain for the next incident

Keep a request identifier that can be followed from the client through NGINX and into the application when your stack supports one. Retain the access-log format with the four timing variables, document the active error-log path, and maintain a map of every proxy and application timeout. That preparation turns the next 504 from a vague gateway error into a phase-specific investigation.

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
PC Slower Than It Used to Be?Free scan - under a minute
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.