nginx returns html instead of json response

Francis Daly francis at
Thu Dec 1 19:47:53 UTC 2022

On Tue, Nov 29, 2022 at 09:58:20PM +0530, Kaushal Shriyan wrote:

Hi there,

> I have a follow up question related to the below error which appears in
> html instead of JSON format when I hit rest api calls
> in case of when the MySQL Database service is down
> as part of testing the end to end flow. The flow is as follows:
> User -> Nginx webserver -> PHP-FPM upstream server -> MySQL Database.
> *The Website Encountered an Unexpected Error. Please try again Later </br>*
> Is there a way to display the above string in JSON format?

The easiest is probably to see which part of the chain creates that error
message (and I guess that it is probably some php); and to change it to
return the error content that you want it to return. And then let
everything else continue to pass the error content through without change.


Francis Daly        francis at

More information about the nginx mailing list