nginx returns html instead of json response

Kaushal Shriyan kaushalshriyan at gmail.com
Tue Nov 22 14:22:41 UTC 2022


Hi Francis,

I tried the below to handle JSON responses from the PHP-FPM backend.

*Line no from 1 to 4(*nginxtest.conf*)*
map $sent_http_content_type $enableerror {
    default                    on;
    application/json          off;
}

*Line no from 46 to 51**(*nginxtest.conf*)*
location = /error-500.html {
             if ($enableerror = "on") {
             error_page 500 /error-500.html;
             root
/var/www/html/gsmaidp/web/servererrorpages/error-pages-500-503/html;
             }
      }

I have attached the nginxtest.conf file for your reference. It is not
working for me. Am I missing anything? Please guide me.

Best Regards,

Kaushal

On Tue, Nov 22, 2022 at 12:53 AM Francis Daly <francis at daoine.org> wrote:

> On Sat, Nov 19, 2022 at 09:09:34PM +0530, Kaushal Shriyan wrote:
>
> Hi there,
>
> > On 500 errors also we are handling at Drupal and sending JSON responses
> to
> > specify the details about errors.
>
> I think that for these api requests, you want to do either one of:
>
> * set fastcgi_intercept_errors off
> * unset error_page for 500
>
> In the below config, I show both. You can probably comment out either
> one of those two lines, without changing things.
>
> Depending on the error indication that you get, you might need to swap
> the order of the "include" an the "fastcgi_param" lines.
>
> So, starting with your original nginx config, add the following stanza
> within the appropriate server{} block, and outside of any other location{}
> blocks. The position of this within the server{} should not matter.
>
>         location ^~ /apis/ {
>                 fastcgi_intercept_errors off;
>                 error_page 555 /dummyfile;
>                 fastcgi_pass 127.0.0.1:9000;
>                 include fastcgi.conf;
>                 fastcgi_param SCRIPT_FILENAME $document_root/index.php;
>         }
>
> Then make some test requests and report either that it works; or that
> it does not work because when you make this specific request, you get
> this specific response, but you want that other response instead.
>
> Good luck with 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/20221122/8399f121/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 3678 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221122/8399f121/attachment.obj>


More information about the nginx mailing list