Question: I suddently get a 502 Bad gateway error and I don't understand why this error appear. This error appear moreover only for 1 single page!!...

The exact error in my Nginx log is :

```
 Upstream prematurely closed FastCGI stdout while reading response header from upstream [..] upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"

```

I tried :

* service nginx restart : NOTHING CHANGE
* service php5-fpm restart : NOTHING CHANGE
* to reboot the server : NOTHING CHANGE
* even to restart the mysql service : NOTHING CHANGE

My /var/log/upstart/php5-fpm.log (only a lot of NOTICES) :

```
Terminating...
exiting, bye-bye!
fpm is running, pid 9887
ready to handle connections
systemd monitor interval set to 10000ms

```

that makes me crazy, any idea ?

Answer: 
Strangely enough, this is what worked for me after chasing down a mysterious 502 Bad Gateway error:

* Change `error_reporting` setting in `php-fpm` ini like this:

`error_reporting = ~E_ALL`
* Then restart `php-fpm` and `nginx`

This worked for me after trying the suggested nginx settings above to no avail. I don't have a verified explanation for this, but it would appear that excessive error reporting can overload the php-fpm process.
Try to `include <fcgi_stdio.h>` in your source file.
This error happens to me just now,then i add `include <fcgi_stdio.h>`in my `c` file,here is my code.

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcgi_config.h>
#include <fcgi_stdio.h>

int main()
{
    int count = 0;
    while(FCGI_Accept() >= 0)
    {
        printf("content-type:text/html\r\n");
        printf("\r\n");
        printf("<title>Fast CGI Hello</title>");
        printf("<h1>fast CGI hello</h1>");

        printf("Request number %d running on host<i>%s</i>\n",++count,getenv("SERVER_NAME"));
    }

    return 0;
}

```