AWS Load Balancer return 502/504 Error & (possible) solution

Are you facing a 502 Bad Gateway problem from your AWS load balancer, while your web server return value successfully?

If so, please read on.

Here is my situation:

- I am using Wordpress 5.8 as backend service

- In WP admin panel we create a PHP function that make an AJAX request, which then called another WP functions, and get JSON string as return.

- But this WP admin panel is behind an AWS Load balancer, which means the URL points to AWS LB first, and the values will be transferred back-and-forth between LB - WP.

Here is the problem: 

When we make an AJAX request, LB returns 502 Bad Gateway in our testing server.  But there is no problem in local development server.

Here is why this problem exists:

- First of all, this is NOT a timeout problem.  

- We tested that web server can handle up to 2 mins long request.  But even if the request just use 7 seconds, it will still return 502.  So setting Keep-alive(timeout) and other server timeout did not work.

- Looking at the response of my response header, I discovered that there are a lot of X-QM-php_errors-error-<error_count> header values included in response.

After reading the following:

Problem, SOLVED!

These X-QM-php_errors header value is coming from a WP plugin called: Query Monitor (QM).  These header values cannot be parsed/understood by AWS LB.

While you can remove those headers by setting it in AWS LB, it is much more simple for me to just deactivate Query monitor.

With that change, problem gone!


Hope it helps someone.

P.S.: Query Monitor is installed by me... XD

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

How to fix fancy box/Easy Fancybox scroll not work in mobile

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services