Re: nginx returns html instead of json response

2022-12-01 Thread Francis Daly
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 > http://mydomain.com/apis in case of when the MySQL Database service is down > as part of t

Re: nginx returns html instead of json response

2022-11-30 Thread Kaushal Shriyan
On Tue, Nov 29, 2022 at 9:58 PM Kaushal Shriyan wrote: > 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

Re: nginx returns html instead of json response

2022-11-29 Thread Kaushal Shriyan
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 b

Re: nginx returns html instead of json response

2022-11-23 Thread Francis Daly
On Wed, Nov 23, 2022 at 11:27:35PM +0530, Kaushal Shriyan wrote: > On Wed, Nov 23, 2022 at 11:20 PM Francis Daly 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/ { >

Re: nginx returns html instead of json response

2022-11-23 Thread Kaushal Shriyan
On Wed, Nov 23, 2022 at 11:20 PM Francis Daly wrote: > On Tue, Nov 22, 2022 at 07:52:41PM +0530, Kaushal Shriyan wrote: > > Hi there, > > > map $sent_http_content_type $enableerror { > > defaulton; > > application/json off; > > } > > I believe that from a timi

Re: nginx returns html instead of json response

2022-11-23 Thread Kaushal Shriyan
On Tue, Nov 22, 2022 at 7:52 PM Kaushal Shriyan wrote: > 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 { > defaulton; > application/json

Re: nginx returns html instead of json response

2022-11-23 Thread Francis Daly
On Tue, Nov 22, 2022 at 07:52:41PM +0530, Kaushal Shriyan wrote: Hi there, > map $sent_http_content_type $enableerror { > defaulton; > application/json off; > } I believe that from a timing point of view, that variable is not going to have a useful value when

Re: nginx returns html instead of json response

2022-11-22 Thread Kaushal Shriyan
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 { defaulton; application/json off; } *Line no from 46 to 51**(*nginxtest.conf*)* location = /erro

Re: nginx returns html instead of json response

2022-11-21 Thread Francis Daly
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 * uns

Re: nginx returns html instead of json response

2022-11-19 Thread Kaushal Shriyan
On Sat, Nov 19, 2022 at 12:02 AM Francis Daly wrote: > On Fri, Nov 18, 2022 at 11:10:20PM +0530, Kaushal Shriyan wrote: > > On Fri, Nov 18, 2022 at 9:37 PM Francis Daly wrote: > > Hi there, > > > Thanks Francis for your email response. Let me explain with two > different > > scenarios :- > > Ye

Re: nginx returns html instead of json response

2022-11-18 Thread Francis Daly
On Fri, Nov 18, 2022 at 11:10:20PM +0530, Kaushal Shriyan wrote: > On Fri, Nov 18, 2022 at 9:37 PM Francis Daly wrote: Hi there, > Thanks Francis for your email response. Let me explain with two different > scenarios :- Yes, thank you. I believe that what you want is still all clear to me, apa

Re: nginx returns html instead of json response

2022-11-18 Thread Kaushal Shriyan
On Fri, Nov 18, 2022 at 9:37 PM Francis Daly wrote: > On Fri, Nov 18, 2022 at 07:07:41PM +0530, Kaushal Shriyan wrote: > > On Thu, Nov 17, 2022 at 10:57 PM Francis Daly > wrote: > > Hi there, > > > Please let me know if you need any additional information and I look > > forward to hearing from y

Re: nginx returns html instead of json response

2022-11-18 Thread Francis Daly
On Fri, Nov 18, 2022 at 07:07:41PM +0530, Kaushal Shriyan wrote: > On Thu, Nov 17, 2022 at 10:57 PM Francis Daly wrote: Hi there, > Please let me know if you need any additional information and I look > forward to hearing from you. Thanks in advance. When the request is for "/apis/unique_id", w

Re: nginx returns html instead of json response

2022-11-18 Thread Kaushal Shriyan
On Thu, Nov 17, 2022 at 10:57 PM Francis Daly wrote: > On Mon, Nov 14, 2022 at 08:24:15PM +0530, Kaushal Shriyan wrote: > > > On Fri, Nov 11, 2022 at 2:38 PM Francis Daly > wrote: > > Hi there, > > > >> What one specific request do you want to make? (Maybe > > >> http://mydomain.com/apis, maybe

Re: nginx returns html instead of json response

2022-11-17 Thread Francis Daly
On Mon, Nov 14, 2022 at 08:24:15PM +0530, Kaushal Shriyan wrote: > > On Fri, Nov 11, 2022 at 2:38 PM Francis Daly wrote: Hi there, > >> What one specific request do you want to make? (Maybe > >> http://mydomain.com/apis, maybe http://mydomain.com/api/v1/*, maybe > >> http://mydomain.com/api/v1/e

Re: nginx returns html instead of json response

2022-11-16 Thread Kaushal Shriyan
On Thu, Nov 17, 2022 at 3:13 AM Sergey A. Osokin wrote: > On Wed, Nov 16, 2022 at 10:29:04PM +0530, Kaushal Shriyan wrote: > > Checking in again if someone can help me with my earlier post to this > > mailing list? Thanks in advance. > > I'd recommend to take a look on the proxy_intercept_errors

Re: nginx returns html instead of json response

2022-11-16 Thread Sergey A. Osokin
On Wed, Nov 16, 2022 at 10:29:04PM +0530, Kaushal Shriyan wrote: > Checking in again if someone can help me with my earlier post to this > mailing list? Thanks in advance. I'd recommend to take a look on the proxy_intercept_errors directive [1], it helps to intercept 300+ error codes and processin

Re: nginx returns html instead of json response

2022-11-16 Thread Kaushal Shriyan
On Mon, Nov 14, 2022 at 8:24 PM Kaushal Shriyan wrote: > > >> On Fri, Nov 11, 2022 at 2:38 PM Francis Daly wrote: >> >>> On Wed, Nov 09, 2022 at 11:45:20PM +0530, Kaushal Shriyan wrote: >>> >>> Hi there, >>> >>> > Checking in again if someone can help me with my earlier post to this >>> > mailin

Re: nginx returns html instead of json response

2022-11-14 Thread Kaushal Shriyan
> On Fri, Nov 11, 2022 at 2:38 PM Francis Daly wrote: > >> On Wed, Nov 09, 2022 at 11:45:20PM +0530, Kaushal Shriyan wrote: >> >> Hi there, >> >> > Checking in again if someone can help me with my earlier post to this >> > mailing list? >> >> The question in the post was, and is, a bit unclear to

Re: nginx returns html instead of json response

2022-11-11 Thread Kaushal Shriyan
Thanks Francis for the email and appreciate it. I will explain in detail about this specific usecase. Thanks once again. On Fri, Nov 11, 2022 at 2:38 PM Francis Daly wrote: > On Wed, Nov 09, 2022 at 11:45:20PM +0530, Kaushal Shriyan wrote: > > Hi there, > > > Checking in again if someone can hel

Re: nginx returns html instead of json response

2022-11-11 Thread Francis Daly
On Wed, Nov 09, 2022 at 11:45:20PM +0530, Kaushal Shriyan wrote: Hi there, > Checking in again if someone can help me with my earlier post to this > mailing list? The question in the post was, and is, a bit unclear to me. You seem to be showing multiple different requests, so I'm not sure exact

Re: nginx returns html instead of json response

2022-11-09 Thread Kaushal Shriyan
Hi, Checking in again if someone can help me with my earlier post to this mailing list? I have a follow up question, when the user invokes -> http://mydomain.com/apis -> Nginx Webserver -> Drupal 9 Core CMS -> PHP-FPM backend server. Nginx should present the below

Re: nginx returns html instead of json response

2022-11-07 Thread Kaushal Shriyan
On Tue, Nov 8, 2022 at 11:20 AM Maxim Dounin wrote: > Hello! > > On Mon, Nov 07, 2022 at 08:59:51PM +0530, Kaushal Shriyan wrote: > > > I am running the nginx version: nginx/1.22 as a reverse proxy server on > > CentOS Linux release 7.9.2009 (Core). Is there a way to return json > > response when

Re: nginx returns html instead of json response

2022-11-07 Thread Maxim Dounin
Hello! On Mon, Nov 07, 2022 at 08:59:51PM +0530, Kaushal Shriyan wrote: > I am running the nginx version: nginx/1.22 as a reverse proxy server on > CentOS Linux release 7.9.2009 (Core). Is there a way to return json > response when i hit http://mydomain.com/api/v1/* instead of the html > response

Re: nginx returns html instead of json response

2022-11-07 Thread Dan G. Switzer, II
Error page doesn't allow a string content as return (at least it's not documented as being valid). Try: location /apis/* {     add_header 'Content-Type' 'application/json charset=UTF-8';     return 500 '{"error": {"status_code": 500,"status": "Internal Server error"}}'; } -Dan On 11/7/2022

Re: nginx returns html instead of json response

2022-11-07 Thread Kaushal Shriyan
On Mon, Nov 7, 2022 at 9:40 PM Dan G. Switzer, II wrote: > The "internal" keyword indicates only internal request can access the > location: > > http://nginx.org/en/docs/http/ngx_http_core_module.html#internal > > So hitting ttp://mydomain.com/api/v1/* with CURL would never hit this > location.

Re: nginx returns html instead of json response

2022-11-07 Thread Dan G. Switzer, II
The "internal" keyword indicates only internal request can access the location: http://nginx.org/en/docs/http/ngx_http_core_module.html#internal So hitting ttp://mydomain.com/api/v1/*  with CURL would never hit this location. Remove the "internal" keyword, reload Nginx and try it again. -Da

nginx returns html instead of json response

2022-11-07 Thread Kaushal Shriyan
Hi, I am running the nginx version: nginx/1.22 as a reverse proxy server on CentOS Linux release 7.9.2009 (Core). Is there a way to return json response when i hit http://mydomain.com/api/v1/* instead of the html response. location /api/v1/* { internal; add_header 'Content-Type' 'applicat