Php site getting 502 bad gateway error

apache-2.2PHPweb-server

I am running a php webapp and consistently get a: 502 bad gateway nginx error when attempting certain function within the site. Without trying to go into detail about what specific code may cause this (cause it could be anything) has anyone ever experienced this with a php/apache setup? Is it a code issue or an admin issue? I am using webfaction as my host.

Update: here is a log of the responses from my host:

This is often a symptom of hitting the maximum concurrent requests on the shared apache instance. If you would like, we can set you up on a private Apache+PHP instance, which should solve this issue for you. It will also have the added advantage of a performance increase, and the slight disadvantage of being counted towards your memory usage.


If you find it is happening consistently on a single function, then the concurrent requests issue is not the problem. It is most likely a time-out of the function you have narrowed it down to.

Your options in this case, are to
either optimise the code for this
function so it responds in a more
timely fashion, or you could look into
the possibility of increasing the
time-out limit during that script's
execution.

Does it seem like they are making any sense with this? I don't know what he means by a function timing out since I developed the app locally on a lamp stack with no time-out problems. Only once I uploaded the application to webfaction did I start getting this error.

Best Answer

Uhm... if it's a PHP/Apache setup, why are you getting an Nginx error message? On the assumption that you meant php/nginx, I'll continue...

Depending on how exactly your webhost has things setup, it could be one of a number of things. Most likely, one of the backend processes they're proxying to is giving 500 errors of it's own (that's pretty much what "Bad Gateway" means), so I'd start with looking into why your backends are sending back 5xx codes in response to requests. Look in the app error logs (to see what errors it is spawning) and nginx error logs (to see what URLs are causing the failures). Lodge a ticket with your hosting provider to get them to look at any logs you don't have access to yourself.

Related Topic