502 bad gateway and codeigniter/nginx/apache. Code or server issue? 502 bad gateway and codeigniter/nginx/apache. Code or server issue? codeigniter codeigniter

502 bad gateway and codeigniter/nginx/apache. Code or server issue?


I figured out what was wrong. First of all, a colleague with more server knowledge explained me that my setup probably was such that nginx received all the requests, and then directly served static files. for non-static request, it passed on the work to apache, and serves as an intermediary. So probably something went wrong when apache tried to send data to nginx (or when nginx tried to send information to apache).

As I never worked with nginx before, I also did not think of checking the nginx log files. And there was an error that I could use:

[error] 27453#0: *9223 upstream sent too big header while reading response header from upstream, client:

I ended up applying the first bit of this other stack overflow solution:

Add this to your nginx.conf file normally located at/etc/nginx/nginx.conf:proxy_buffer_size   128k; proxy_buffers   4 256k;proxy_busy_buffers_size   256k;

By the way, it should be added to the http section of the file. That was something what was missing from the solution.


I would recommend checking Apache server status right after failure (service httpd status). Not much details for better judgement, but one of likely scenarios would be that Apache fails on Nth request, so Nginx cannot forward request to Apache and returns "502 Bad Gateway" to you.

The Apache failure may be both programmatic and misconfiguration issue. i.e. it takes too much RAM on Nth request (my understanding that you keep some date between requests) and then is killed by virtualization engine (in case you have VPS rather than dedicated hardware server). Just a hypothesis so far, but I have experienced cases like that before.