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

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

When a website fails on a Linux server, start at the service boundary rather than changing random application settings. Check nginx and the application service with systemctl status, read their complete logs with journalctl, inspect nginx’s error log, and verify that the upstream process is listening. The HTTP code usually narrows the fault: 502 means nginx could not obtain a valid upstream response, 503 often means nginx deliberately rejected traffic, and 504 means an upstream response took longer than the configured read timeout.

This guide follows that evidence-first order. It shows what to run, what each result means, and when a restart, socket-permission correction, SELinux investigation, or timeout change is justified.

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

Start with a five-minute triage

  1. Check nginx. Run sudo systemctl status nginx. Read the Active state and the Result field. A result such as exit-code indicates that the unit stopped with an error; timeout indicates that systemd waited unsuccessfully for an operation.
  2. Check the backend. Replace the example unit with the service your site uses, such as PHP-FPM or an application server: sudo systemctl status <backend>.
  3. Read the full service journal. The lines shown by systemctl status are only a recent excerpt. Use sudo journalctl -u nginx and, separately, sudo journalctl -u <backend> --since "5 minutes ago".
  4. Inspect nginx’s error log. The commonly used path is /var/log/nginx/error.log. Match its message and timestamp with the HTTP error returned to the browser.
  5. Verify the upstream listener. Run sudo ss -tlnp. Confirm that the port or Unix socket in the nginx configuration actually has a listening process.

Do not restart repeatedly before collecting evidence. A restart can remove the immediate symptom while leaving the cause—and can make a previous-boot investigation harder.

What the main HTTP errors mean

Status Meaning at the nginx proxy First evidence to inspect Typical next action
502 Bad Gateway Nginx could not connect to the upstream, received an invalid response, or the upstream closed the connection before completing it. Nginx error log, backend status and journal, listener and socket checks. Start or repair the backend, correct the socket path or access policy, and investigate crashes or malformed responses.
503 Service Unavailable Nginx may be rejecting traffic intentionally because a rate or connection limit was reached; it is not automatically proof that the backend is down. Nginx error log for a limiting requests message, including the IP and limit zone; then check backend health. Determine whether a configured limit is being reached or whether a separate backend failure exists.
504 Gateway Timeout Nginx connected to the upstream but did not receive the next part of the response before its read timeout expired. Error-log timing, backend journal, request duration and the effective proxy timeout in the matching configuration block. Fix slow or stuck application work first; raise the timeout only when the longer response is expected and safe.

Why a 502 is different from a 504

A 502 is a connection or protocol failure. The error log commonly includes a message such as connect() failed (111: Connection refused) when no process accepts the configured upstream connection. It can also occur after a connection if the upstream sends an invalid response or closes early.

#1 Best Overall
Sale
Compressed Air Duster,130000RPM Super Power Cordless Air Duster,Rechargeable Brushless Blower,3 Gear Adjustable Blower with LED Light,Dust Remover for Computer/House/Outdoor/Car
  • Powerful Turbo Fan:CAGIWIRU Electric Air Duster have reached speed up to 130000RPM,Can efficient remove dust and debris.With LED light and Three Adjustable Speed to meet with different cleaning tasks.
  • With Attached USB C Fasting Charging cable.Charing 3 hours,Enjoy up to 240 minutes of use on the lowest setting, For third speed can use for 25mins.with four charging options to meet with your needs.
  • Wide Application:Upgraded attached 5 different nozzles,making it suitable for a variety of scenes, such as car,pet, pc, keyboards, and other electronic devices. It also serves for office and home clean duster.
  • Handy Design & Portable:Cordless air duster electric nozzle is Light weight and small size, design and comfortable to hold and space saving, convenient to carry around. You can put it in your room or inside the car without taking up space.
  • Warranty & Support: Our Electric air duster comes with 5 years warranty and 24/7 customer service. During this period, if you have any questions,pls kindly feel free to contact us.

A 504 indicates that the connection succeeded but nginx waited too long for data. The default proxy_read_timeout is 60 seconds in nginx. This is an inactivity interval between successive reads, not a cap on the total time a response may take. A backend that sends data periodically can therefore run longer than 60 seconds without hitting this particular limit.

Why a 503 may be deliberate

Nginx can return 503 when rate or connection limits reject a request. In that case the error log records a limiting message and identifies the client address and configured zone. Treat that evidence differently from a stopped service: inspect the limit configuration and traffic pattern before restarting anything.

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

Check systemd service state and history

Read the current unit state

Run:

sudo systemctl status nginx
sudo systemctl status <backend>

Look for whether the unit is active, failed, activating, or repeatedly restarting. The Result field helps classify the failure, but it is not a complete diagnosis. The status view displays only a short tail of recent messages, so continue with the journal.

Read the complete nginx journal

Use the following views to widen or narrow the time range:

sudo journalctl -u nginx
sudo journalctl -u nginx --since "30 minutes ago"
sudo journalctl -u nginx -b -p err

The first command shows the unit’s available journal entries. The second is useful when the outage began recently. The third filters the current boot to error priority. If the server was rebooted during the incident, inspect the previous boot:

sudo journalctl -u nginx -b -1

Apply the same approach to the backend, for example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
EVEO® Screen Cleaner Spray Kit (Streak-Free) TV Screen Cleaner for Smart TV, Lcd, LEd, Oled | Computer Screen Cleaner Spray and Wipe Microfiber Cloth - TV, Monitor, Laptop, iPad, Car - 6.7oz 1 Pack
  • Screen Cleaner is Your Screen’s New Bestfriend! - EVEO is proud to present a screen cleaner that’s perfectly suited for your TV. Meet your new screen cleaner, computer screen cleaner, laptop cleaner, iPad cleaner, Macbook,tv cleaner or any other electronic device. Our screen cleaner spray and wipe along with the included plush microfiber cloth, easily removes dust, fingerprints & other smudges on the screen’s surface. Clean effectively for a streak-free screen
  • Gentle on your Screens - Our screen cleaner spray and wipes is compatible to be used even for the most sensitive LCD, LED, CRT, and OLED screens in proper use. Be at ease knowing that this product is compatible with all the major brands: LG, SONY, Samsung, Sharp, iPad, iPhone, Android screens, Kindle, PC monitors - we’ve got you covered! Can be used as LCD screen cleaner, tv cleaner, smart tv screen cleaner, and more
  • Premium Super Soft Plush Microfiber Cloth - Included in this efficient screen cleaning kit. This screen cleaner spray and wipe has our signature plush microfiber cloth specially designed to comply with screens and monitors and leave them streak-free. Has been shown to effectively absorbs stubborn stains, zero streaks, and no fiber shedding. Always use this together with our screen cleaner for the best results
  • Easy-to-Use Screen Cleaner Kit + microfiber cleaning cloth - The EVEO Screen Cleaning Kit will easily be your new favorite tool when it comes to taking care of the things you love most, quick and easy solution for a streak-free screen. Simply screw on the sprayer gun on the screen cleaner bottle. Spray the cleaning liquid onto the microfiber cloth, then wipe the screen until desired cleanliness & shine is achieved.
  • Quality Screen Care Kit Worth Purchasing - Enjoy a convenient Screen Cleaner anytime, anywhere you need it. Your satisfaction is our top priority. We stand behind the quality of our products and that’s why, you shouldn’t be worrying at all. We manufacture the Best Screen Cleaner. and can be used for laptop cleaning kit, laptop screen cleaner, tv screen cleaner for smart tv. MacBook screen cleaner, monitor cleaner or screen cleaner spray for electronic devices with microfiber cleaning cloth
sudo journalctl -u php-fpm --since "5 minutes ago"

Use the service name installed on your distribution; it may include a version suffix. If the backend journal shows a crash, out-of-memory termination, or repeated startup failure, fix that service before changing nginx proxy settings.

Use the nginx error log as the request-level record

Open the error log commonly located at /var/log/nginx/error.log, or use the path configured for your virtual host. Correlate an entry’s timestamp with the failed request and with the systemd journal. The wording often tells you whether nginx could not connect, received a bad upstream response, hit a limit, or timed out.

Capture the complete line, including the upstream address or socket and the client-facing URI. Those details distinguish a single broken location from a server-wide outage. For example, a refusal on a PHP-FPM socket points to the PHP-FPM process or socket access, while a timeout to a network address points toward a slow or stuck upstream.

Verify that the backend is actually listening

Inspect TCP listeners

Run:

sudo ss -tlnp

Compare the listening address and port with the upstream target in the nginx configuration. A process listening only on 127.0.0.1 cannot be reached through an address bound only to another interface. Conversely, nginx may be configured for a port where no process is listening.

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

Check Unix sockets

PHP-FPM and other local services often use a Unix socket instead of TCP. Confirm that the configured socket file exists and that its owner, group, and mode allow the nginx worker process to open it. A user or group mismatch is a commonly reported cause of 502 responses. Verify the effective nginx worker account and the backend pool’s socket settings rather than broadening permissions blindly.

Compare service and configuration targets

It is possible for the backend to be healthy while nginx points to an old socket path, an unused port, or a service instance from a different version. Treat the target in the active server and location block as authoritative; do not assume that a similarly named process is the one nginx uses.

Rank #3
BladeHawks RGB Gaming Mouse Pad Extra Large Extended 31.5x12 Inch-Black
  • 【Large size】:Measuring 800 x 300 mm/ 31. 5×12 inches, which is wider and taller than others. Large mouse pad can perfectly fit your keyboard and mouse of any size, and there is also ample space for peripherals such as phones, tablets, etc.
  • 【LED backlight mouse pad】:Blade Hawks RGB mouse pad provides 7 static modes and 7 dynamic modes will give you the options you are looking for. Power-off memory function remembers the last lighting mode you selected. The super glow fiber Chroma will give you a colorful gaming setup that you want.
  • 【Anti-slip rubber base】:Made from Natural rubber, this gaming mousepad will firmly grip your desktop, allowing you to enjoy the ultimate precision in the games you are most passionate about. It also comes with a texture that enhances this ability even further.
  • 【Smooth and waterproof surface】: Micro-textured cloth surface, for extremely precise mouse control and a smooth movement. When liquid splashes on the gaming mouse pad, it forms water droplets and slides down. Will not delay your work or gameplay.
  • 【Plug and play】: This mouse and keyboard pad is powered by USB, plug and play, no driver required. One button control light modes. Press one time to change the lighting mode, press twice to change the brightness, press and hold about 3 seconds turn ON/OFF.

Fixing 502 Bad Gateway errors

Backend stopped or failed to start

For a PHP site, check the PHP-FPM unit:

sudo systemctl status php-fpm
sudo journalctl -u php-fpm --since "15 minutes ago"

If the service is stopped and the journal identifies a recoverable configuration or dependency issue, correct that issue and start the service. A restart is appropriate after the cause is understood:

sudo systemctl restart php-fpm

Then make one controlled request and check the nginx error log again. If PHP-FPM immediately exits, the application service’s journal is more valuable than repeated nginx restarts.

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

Socket access denied

When the error log indicates permission denial on a Unix socket, check all path components and the socket’s owner and group. The nginx worker must be able to traverse the directories and open the socket. Align the backend pool’s socket ownership and mode with the account nginx actually uses, then restart the backend if it recreates the socket at startup. Avoid making a socket world-writable as a first response; that can create a broader security problem.

Malformed or prematurely closed responses

A backend can be running and listening yet still produce 502 if it crashes while handling a request, closes the connection, or emits a response nginx cannot parse. Look for application exceptions, worker exits, and memory-related messages at the same timestamp. Reproduce with a narrow endpoint or health check so you can distinguish one failing request from a service-wide protocol problem.

SELinux policy on RHEL-family systems

On Red Hat Enterprise Linux-family systems, SELinux can block nginx from making a network connection even when the backend and port are correct. Check the relevant boolean:

getsebool httpd_can_network_connect

If policy denials appear in the system audit records, involve the system’s SELinux policy rather than disabling enforcement as a shortcut. Confirm which process and destination were denied, apply the least-privileged policy change approved for your environment, and retest the request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Vaydeer Wrist Rest for Keyboard and Mouse, Computer Ergonomic Wrist Support Pad, Soft Memory Foam Arm Cushion for Desk, Palm Hand Office Laptop Typing
  • 【Softer and More Comfortable】Vaydeer wrist rest has unique diamond pattern, which is the combination of softness and aesthetics. The materials of wrist rest are improved into higher quality memory foam and covered with silky smooth lycra. The computer wrist rest makes you as comfortable and cushiony as like rest your wrists on clouds.
  • 【Ergonomic Wrist Saver】The wrist rests for keyboard and mouse comes with a 17.32×3.15×0.83 inch keyboard wrist pad and a 5.94×3.15×0.83 inch mouse wrist support. Based on ergonomic design, the unique concave shape is the perfect fit for your wrist joints. The wrist rest pad fits most computer keyboards and laptops, improve hand and wrist posture, release your wrist and arm stress.
  • 【Non-Slip Rubber Bottom】Featuring an anti-skid silicone base on the bottom, this wrist keyboard support stays firmly in place on your desk, preventing the padding from sliding around, ensuring stable and consistent wrist support during extended computer sessions.
  • 【Better Experience & Pain Relief】Our keyboard arm rest is beneficial to alleviate the soreness caused by direct contact and friction between your arm and a hard desk surface, reducing the risk of wrist fatigue or carpal tunnel. The soft texture of memory foam can evenly distribute the pressure around your wrists and provide good support with just enough give.
  • 【Helpful in Multiple Scenarios】Whether you're working, studying, writing, typing, gaming, this keyboard and mouse rest combo is an essential accessory to add comfort and support to your hands and wrists. It’s also a great gift for men, women, family, friend, coworker, gamer, teacher, etc.

Fixing 503 Service Unavailable responses

Look for nginx limiting messages

Search the error log around the failure for wording such as limiting requests. The entry should identify the offending client address and the limit zone. This confirms that nginx intentionally generated the 503 because a configured rate or connection threshold was reached.

Check whether a burst of legitimate traffic, a retry loop, or one misbehaving client is consuming the allowance. Adjust limits only after confirming the intended capacity and abuse-control policy. Raising a limit can move overload from nginx to the backend, so watch backend latency and resource use while testing.

Separate limiting from backend failure

If no limiting entry exists, inspect the backend status and journal. A stopped or overloaded upstream can produce a service-unavailable response through application or proxy configuration, but the remedy is different from a rate-limit event. Use the timestamp and request path to identify which layer generated the response.

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

Fixing 504 Gateway Timeout responses

Confirm the timeout interval

Nginx’s default proxy_read_timeout is 60 seconds. The directive measures the gap between two reads from the upstream. It does not measure the complete lifetime of a request, and increasing it cannot make a computation faster.

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

Inspect the effective configuration for the server and location that handled the request. A setting in an unrelated block will not affect the failing route. An nginx ticket described a report of a 45-second 504 despite an override; the ticket was closed as invalid, and the reported workaround was to place the directive in the location block that actually matched. Treat an apparently ignored override as a configuration-scope problem first.

Decide whether the application is slow or stuck

Check application logs and request timing. A genuinely long report, export, or upstream API call may need a larger inactivity interval. A worker waiting on a dead dependency, lock, or exhausted pool needs an application fix instead. Increasing the timeout for a stuck operation consumes connections and can worsen an outage.

Best Value
Sale
Under Desk Cable Management Tray No Drill, Metal Mesh Cable Management Under Desk with Clamp Mount, 2 Hole Cable Tray with Wire Management and Cord Organizer for Home Office Standing Desk
  • 【No Drill Mounted】Cable management tray can be assembled in as little as 3 minutes or less-simply. Side clips easily clampe the edge of desk, pass through the holes on the sides, and secure excess cables with baskets. Desk cable management supports inward or outward installation to meet your needs in different scenarios, and provides you with great convenience when collecting and organizing wires.
  • 【Rubber Pad Protects Desk】Wire organizer under desk built-in soft rubber pads on the clamp protect your desk from scratches, so you will not damage your furniture or office.
  • 【Sturdy and Beautiful】Cord management under desk is made of high-quality carbon steel and holds about 15 lbs. The wire basket has 2 holes on each side of the tray to enable your cables to pass freely. Cable baskets are suitable for desk thickness use from 0.4" to 2.4".
  • 【Space Saving & Keep Organized】Desk cable management tray holds all your power cords, outlet strips, USB hubs and computer transformers hidden from your feet, and the data cables will not enter the vacuum cleaner to keep your desk clean and tidy. Desk wire organizer is also suitable for use in the kitchen and outdoors.
  • 【Reduce Safety Risks】Cable tray under desk keeps all plugs away from your kids, no more worry about tripping. Using 2 holes wire tray saves extra space, helps you easily cabling and wire protection. The mesh design is not easy to accumulate dust, but avoids safety accidents caused by messy wires.

Apply a targeted timeout change

Place a deliberately chosen value in the matching proxy location, test the nginx configuration, and reload rather than restarting the whole host:

proxy_read_timeout 120s;

Use a value appropriate to the endpoint’s expected behavior and capacity. After reloading, verify that the request reaches the intended block and monitor both nginx and backend logs. For WebSocket proxying, remember that an idle connection is closed after the read timeout by default if the proxied server sends no data; configure an interval compatible with the protocol’s heartbeat behavior.

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

Safe change, reload, and rollback procedure

  1. Record the exact error, URL path, timestamp, status code, upstream target, and current service state.
  2. Make one narrowly scoped change: start the failed backend, correct its socket access, adjust the matching limit, or change the matching timeout.
  3. Validate nginx configuration before applying it: sudo nginx -t.
  4. Reload nginx when the change is configuration-only: sudo systemctl reload nginx. Restart only when a reload cannot apply the change or the service itself is unhealthy.
  5. Send a single controlled request, then immediately review journalctl -u nginx, the error log, and the backend journal.
  6. If the symptom changes or worsens, revert the last change and restore the previously known-good configuration. Keep the captured logs so the next investigation starts with evidence.

When the first checks do not find the cause

Compare layers instead of guessing

If nginx is active, the backend is listening, and no obvious policy denial appears, compare a direct backend request with the same request through nginx. A direct success combined with a proxy failure points toward nginx’s upstream target, permissions, limits, or timeout. A direct failure points to the application or its dependency chain.

Check for repeated crashes and memory pressure

Repeated backend restarts, worker exits, and out-of-memory messages belong in the application-service investigation. Record whether failures occur only under concurrent traffic or on a particular route. Do not treat a successful manual restart as proof that capacity is adequate.

Check the exact configuration block

Proxy directives are inherited and overridden by context. A value in a broad server block may be replaced in a location block, and a location-level setting affects only requests that match it. Confirm the active virtual host and route before concluding that nginx ignored a directive.

Limits of this diagnostic path

This procedure focuses on a Linux web service with nginx as the proxy and a local or network backend. The evidence available for it does not establish a universal error-log path or format, and distributions can place service units and logs differently. It also does not provide a complete procedure for Apache, DNS records, TLS certificates, file ownership outside backend sockets, or a full-disk condition. If nginx and the backend show no corresponding failure, investigate those surrounding layers using the tools and documentation for your distribution and hosting environment rather than forcing every outage into a 502, 503, or 504 explanation.

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.

A practical decision checklist

  • Nginx unit failed: read systemctl status nginx and the full nginx journal, correct the reported cause, then validate and reload or restart.
  • Backend unit failed: inspect its journal for crashes, configuration errors, or memory exhaustion before changing proxy settings.
  • 502 with connection refused: verify the backend listener, port, socket path, and service state.
  • 502 with permission denial: check nginx’s worker account, socket ownership, directory traversal, and SELinux denials where applicable.
  • 503 with a limiting message: investigate the configured rate or connection zone and the traffic pattern; do not assume a crash.
  • 504 at roughly 60 seconds: inspect backend latency and the matching proxy_read_timeout; raise it only for a known, legitimate long-running response.
  • Timeout override appears ineffective: verify the exact server and location block that matched the request.

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.