Upstream service php-fpm is up and running but reports {"errors": {"status_code": 502,"status": "php-fpm server is down"}}

Maxim Dounin mdounin at
Thu Dec 15 20:08:15 UTC 2022


On Thu, Dec 15, 2022 at 09:53:11PM +0530, Kaushal Shriyan wrote:

> I am running the nginx version: nginx/1.22 as a reverse proxy server on
> CentOS Linux release 7.9.2009 (Core). When I hit I
> see the below message on the browser even if the upstream server php-fpm
> server is up and running.
> *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*
> I have set the below in the nginx.conf file and attached the file for your
> reference.
> if ($upstream_http_content_type = "") {
>                      add_header 'Content-Type' 'application/json' always;
>                      add_header 'Content-Type-3'
> $upstream_http_content_type$isdatatypejson"OK" always;
>                       return 502 '{"errors": {"status_code": 502,"status":
> "php-fpm server is down"}}';
>                   }

The "if" directive makes it possible to conditionally select 
configuration to handle a request, and therefore can only use 
information available before the request is handled.  In your 
case, before the request is sent to the upstream server.  See for 
more details.

As such, $upstream_http_content_type will be always empty, since 
there are no upstream response yet, and therefore the 
configuration will always return 502.  This matches your 

An obvious fix would be to remove the configuration chunk in 

Instead, you probably need something like:

    error_page 502 /502.json;

    location = /502.json {
        return 200 '{"errors": {"status_code": 502, "status": "php-fpm server is down"}}';

Hope this helps.

Maxim Dounin

More information about the nginx mailing list