skip to Main Content

My codeigniter application is running against a 502 bad gateway error. I know there are other threads on this subject, but I am no server wizard, the symptoms are different and my server config is slightly different as well, or so I think.

This is my situation.

  • The application works fine, until I post a form for the nth time (n being anywhere between 2 and n times). This nth time is exactly the same as the earlier postings. I just change one field and then press the submit button.
  • The form uses the validation class, and I customized the error message setter in such a way that these messages are also set as flashdata in the session (I want the messages to be available after a redirect).
  • My server uses Nginx and apache (Plesk, apache service daemon is called httpd). If I do “service httpd stop” or “service nginx stop” all my websites stop working immediately.
  • There are no errors in the error log.

My question is this: Could this be a coding issue, or is it most definately (or most likely) a misconfiguration of the server? If it is the latter, all advice is welcome of course, but remember it is a plesk/apache/nginx environment.

Hope you guys can help!

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search