nginx returns html instead of json response

Francis Daly francis at daoine.org
Mon Nov 21 19:21:06 UTC 2022


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



More information about the nginx mailing list