Proxy Error 502 Reason Error Reading From Remote Server With Apache

Maintaining a server is hard.

You have to deal with all the upgrades, security patches and the occassional server errors (aka errors from hell).

One such common error in Nginx servers is "502 Bad Gateway".

502 bad gateway Nginx

three word fault message – because Nginx doesn't honey you. That'southward why.

The fault message is cryptic.

So, many web masters gyre upwards their sleeves and look at the error log:

2017/04/04 08:34:43 [error] 949#949: *7 connect() failed (111: Connexion refused) while connecting to upstream, client: XXX.XXX.XXX.Thirty, server: myserver.com, request: "Get /myurl-this/ HTTP/1.0", subrequest: "/redis-fetch", upstream: "redis://127.0.0.ane:6379", host: "refserver.com", referrer: "http://referalsite.com/myurl-this/"

Yes, more gibberish.

Yous know something is messed upwards, because it says "failed" and "refused".

Just WHAT? You hardly have time to go a PhD in informatics.

Hither's help. Nosotros've listed the top five reasons for502 Bad Gateway error, and how nosotros gear up them.

1. Backend service failed

Nginx depends on backend services like PHP-FPM, database services and enshroud servers to run web applications.

And so, if any of these services crash or freeze, Nginx won't go any data from them, resulting in "502 Bad gateway" error.

Some services that we've seen to fail are:

  • PHP
  • Apache
  • Cache
  • Database

The reasons for service failure tin can range from traffic spikes and resources limits to disk errors and DDoS attacks.

If you suspect a backend service is unresponsive or failed, you tin try killing all unresponsive processes and restarting the service.

For instance, here'south one way we impale defunct PHP-FPM processes and restart services.

# kill -9 $(pgrep php-fpm)
# /etc/init.d/php-fpm restart
* Restarting PHP FastCGI Procedure Manager php-fpm        [ OK ]

Warning : Do non use these commands if you are not sure how it works.

If the service restart didn't work, you may demand to get someone to take a closer look at the server wellness.

Our Nginx experts are online 24/vii. Click hither if you need help resolving your server error.

ii. High server load

The second well-nigh common reason for "502 bad gateway" in Nginx is loftier load boilerplate in backend servers.

Load spikes cause services to not respond.

Nosotros've seen these reasons for load spikes:

  • Sudden fasten in website traffic (can be seasonal or marketing / promotional).
  • Malware infection on the server.
  • Comment spamming or other vulnerability exploits.
  • Creature force attacks that'due south designed to exploit spider web apps.
  • Application bugs that cause retentiveness leaks or resource hogging.

To troubleshoot a high load issue, first we figure out which resource is being abused (I/O, Memory, CPU or Net).

The nosotros detect out which service is abusing that resource, and from that point, detect out which user in that service owns the abusive script or software.

Click here to know more most loftier load troubleshooting.

If your server is currently nether high load, and you demand urgent assistance, click here to contact our Emergency Server Support techs. Nosotros are online 24/7 and can assist y'all in a few minutes.

3. Incorrect service configuration

Your Nginx server and the backend services relies on many sub-systems to work properly.

This includes DNS resolution, Apache processes, PHP services, DB server, etc.

If even one of these services have a wrong config entry, that service will fail to respond, and Nginx will show "502 bad gateway" error.

Some configuration issues that we've seen are:

  • DNS resolver misconfigured in Nginx causing domain lookups to fail.
  • DB login details gear up incorrectly after a contempo migration, restore or upgrade.
  • Apache firewall settings (mod_security) syntax fault causing Apache to crash.
  • Incorrect memory or file limits set for PHP applications.
  • Capacity limits (similar no: of connections per IP) set too restrictively causing legit visits to fail.
  • ..and more

There is no easy manner to find out a configuration error.

You really need to scan the error log and pay attention to what the error says.

For eg. this error here says the PHP awarding reached the maximum limit of processes (defined past pm.max_children setting) immune.

WARNING: [mysite.com] server reached max_children setting (thirty), consider raising it
Mistake: unable to read what child say: Bad file descriptor (nine)

If yous are not familiar with PHP or web server settings, it is all-time to ask a server administrator.

If you lot need aid fixing a similar error, click hither to talk to our Nginx admins. Nosotros are online 24/7 and can attend your ticket within a few mins.

How Bobcares prevents configuration errors

As a quick aside, hither's how nosotros forbid server errors related to config issues.

Configuration errors are generally caused by stale server settings that's not adjusted for new traffic or site upgrades.

That is why Dedicated Server Admins inspect our client servers at least one time a month.

During this inspect, we notice possible performance bottlenecks, security loopholes and hardware issues.

This helps united states of america to proactively resolve potential bug, rather than reacting to a downtime once an mistake has happened.

iv. Service port blocked in firewall

Firewalls are the bedrock of server security. Only if not setup right, these firewalls tin cause legitimate requests to be blocked or services to neglect.

For instance, in Linux servers that run Plesk automation suite, Nginx runs on port lxxx, and Apache runs on port 7080.

But firewalls past default cake uncommon ports such as 7080, and information technology will result in Nginx unable to connect to Apache.

Effect?502 Bad Gateway error.

Such issues oft happens when a new service is enabled (eg. caching server, Ruby, etc.) in the backend, or during a migration, or after a server upgrade.

To gear up information technology, nosotros look at what port each service runs on using a command like this:

# netstat -lpn
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      19785/nginx
tcp6       0      0 :::eighty                   :::*                    Listen      19785/nginx

and if nosotros observe whatever service running in not-standard ports, we either modify the service configuration to modify it to a standard port, or edit firewall config to allow the not-standard port.

5. Spider web application bugs

A rare case for "502 Bad Gateway" error is awarding code fault.

If your spider web server logs bear witness a scary looing mistake similar this, it is possible that our awarding lawmaking is incompatible with the server version.

[notice] child pid 27831 leave signal Segmentation fault (11)

You'll demand to inspect the software requirements of your awarding, and re-configure the services to lucifer the required versions.

If you lot're facing this result right now, our Nginx experts can help yous in a few minutes. Click here to open up a support asking. We are online 24/7.

In Summary

502 Bad Gateway in Nginx commonly occurs when Nginx runs as a reverse proxy, and is unable to connect to backend services. This can be due to service crashes, network errors, configuration problems, and more. Today we've seen the top 5 causes for this error, and how to ready information technology.

jonesformad.blogspot.com

Source: https://bobcares.com/blog/502-bad-gateway-nginx/

0 Response to "Proxy Error 502 Reason Error Reading From Remote Server With Apache"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel