nginx returns html instead of json response
Kaushal Shriyan
kaushalshriyan at gmail.com
Tue Nov 29 16:28:20 UTC 2022
Hi Francis,
Thanks a lot for all your help and support. It worked. I have configured
the below settings in nginx after a few attempts by tweaking it. It worked
like a charm.
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
On Wed, Nov 23, 2022 at 11:39 PM Francis Daly <francis at daoine.org> wrote:
> On Wed, Nov 23, 2022 at 11:27:35PM +0530, Kaushal Shriyan wrote:
> > On Wed, Nov 23, 2022 at 11:20 PM Francis Daly <francis at daoine.org>
> wrote:
>
> Hi there,
>
> > I am not sure about this line error_page 555 /dummyfile; what does 555
> > code mean and what will be the contents of dummyfile?
> >
> > location ^~ /apis/ {
> > fastcgi_intercept_errors off;
> > error_page 555 /dummyfile;
> > fastcgi_pass 127.0.0.1:9000;
> > include fastcgi.conf;
> > fastcgi_param SCRIPT_FILENAME
> > /var/www/html/gsmaidp/web/index.php;
> > }
>
> I thought I had explained it in the previous mails?
>
> 555 is an error code that you do not care about (because you do not
> expect to see it).
>
> You can remove either the "error_page" or the "fastcgi_intercept_errors"
> line (or leave them both in).
>
> What happened when you tried it?
>
> f
> --
> Francis Daly francis at daoine.org
> _______________________________________________
> nginx mailing list -- nginx at nginx.org
> To unsubscribe send an email to nginx-leave at nginx.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221129/c2d7f5cf/attachment.htm>
More information about the nginx
mailing list