nginx returns html instead of json response
| From: | Kaushal Shriyan | Date: | Wed, 30 Nov 2022 23:10:55 +0000 |
| Subject: | nginx returns html instead of json response | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-328099@lists.php.net to get a copy of this message | ||
Hi,
I have configured the below settings in nginx after a few attempts by
tweaking it.
location /apis {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
fastcgi_intercept_errors off;
add_header "X-Debug-JSON-APIS" $http_accept always;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
}
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
http://mydomain.com/apis 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?
Please guide me. Thanks in advance.
Best Regards,
Kaushal