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' 'application/json charset=UTF-8';
error_page 502 '{"error": {"status_code": 502,"status": "Bad
Gateway"}}';
}
But whenever I try to send a request to /api/v1/users via curl I get the
HTML source code in response instead of JSON response.
Please guide me. Thanks in advance. I look forward to hearing from you.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/e440e21b/attachment.htm>
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.
-Dan
On 11/7/2022 10:29 AM, Kaushal Shriyan wrote:
> 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/*
> <https://url.emailprotection.link/?bwxIfDuJKR1YH1mqneKAbav55uYd8-63cvdvlSLvw0mVdAEtaFGRd2iiGoI8nWnhImkBUGplq84IGc2dX0eDK2g~~>
> instead of the html response.
>
> location /api/v1/* {
> internal;
> add_header 'Content-Type' 'application/json charset=UTF-8';
>
> error_page 502 '{"error": {"status_code": 502,"status": "Bad
> Gateway"}}';
> }
>
> But whenever I try to send a request to /api/v1/users via curl I get
> the HTML source code in response instead of JSON response.
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
>
> Best Regards,
>
> Kaushal
>
>
>
> _______________________________________________
> nginx mailing list --nginx at nginx.org
> To unsubscribe send an email tonginx-leave at nginx.org
--
Dan G. Switzer, II
Giva, Inc.
Email:dan.switzer at givainc.com
Web Site:http://www.givainc.com
See Our Customer Successes
http://www.givainc.com/customers-casestudies.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/952a2ed8/attachment.htm>
On Mon, Nov 7, 2022 at 9:40 PM Dan G. Switzer, II <dan.switzer at givainc.com>
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.
>
> Remove the "internal" keyword, reload Nginx and try it again.
>
> -Dan
>
Thanks Dan for the email response.I am still seeing the below response in
html format. I am attaching the nginxtest.conf file for your reference.
*/var/log/nginx/access.log*
48.219.29.210 - - [07/Nov/2022:17:33:38 +0000] "POST /apis HTTP/1.1" 500
1678279 "-" "PostmanRuntime/7.29.2" "-"
*Response in html format*
############################################################################################################
<!doctype html>
<html lang="en">
<head>
<title>500</title>
<meta charset="utf-8">
<meta name="description" content="500">
<link rel="preconnect" href="https://fonts.gstatic.com">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="favicon.ico" type="image/gif" sizes="32x32">
<style>
@font-face {
font-family: "UniversNextHSBC-Light";
src:
url("/themes/custom/gsmamarketplace/font/UniversNextforHSBCW29-Light.woff2")
format("woff2");
}
</div>
<div class="error-content">
<h1>500 <br> Internal server problem</h1>
<p>Sorry, An error occurred and your request couldn't
be completed. <a href="/">Return to the home
page</a></p>
</div>
</div>
</div>
</body>
</html>
############################################################################################################
Please guide me. Thanks in advance. I look forward to hearing from you.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/aef313a1/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 3646 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/aef313a1/attachment.obj>
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 12:47 PM, Kaushal Shriyan wrote:
>
>
> On Mon, Nov 7, 2022 at 9:40 PM Dan G. Switzer, II
> <dan.switzer at givainc.com> wrote:
>
> The "internal" keyword indicates only internal request can access
> the location:
>
> http://nginx.org/en/docs/http/ngx_http_core_module.html#internal
> <https://url.emailprotection.link/?bKzOBHGoVTgMZbVl06OjtjX6aHusF64x7ioKV57xsa8lK5HrhUog6H03w4i49Ibf0uYwbM9e74mZ2RElJBcCfPJ4yQW6AkMPmgxM2SKhEDl3WxQF7mffOIcAwcvVg3N1I>
>
> So hitting ttp://mydomain.com/api/v1/*
> <https://url.emailprotection.link/?bwxIfDuJKR1YH1mqneKAbav55uYd8-63cvdvlSLvw0mVdAEtaFGRd2iiGoI8nWnhImkBUGplq84IGc2dX0eDK2g~~>
> with CURL would never hit this location.
>
> Remove the "internal" keyword, reload Nginx and try it again.
>
> -Dan
>
>
> Thanks Dan for the email response.I am still seeing the below response
> in html format. I am attaching the nginxtest.conf file for your
> reference.
>
> _/var/log/nginx/access.log
> _
> 48.219.29.210 - - [07/Nov/2022:17:33:38 +0000] "POST /apis HTTP/1.1"
> 500 1678279 "-" "PostmanRuntime/7.29.2" "-"
>
> _Response in html format_
> _
> _
> ############################################################################################################
> <!doctype html>
> <html lang="en">
>
> <head>
> <title>500</title>
> <meta charset="utf-8">
> <meta name="description" content="500">
> <link rel="preconnect" href="https://fonts.gstatic.com
> <https://url.emailprotection.link/?by-dLw9LwJmO5vEZpHedagRmqu5Hzr5-4SwcSmbg7a4wCJN60WQwnE73R4jiVqy2JURqdMNsclU-C1XzywjIrkQ~~>">
> <meta name="viewport" content="width=device-width, initial-scale=1.0">
> <link rel="icon" href="favicon.ico" type="image/gif" sizes="32x32">
> <style>
> @font-face {
> font-family: "UniversNextHSBC-Light";
> src:
> url("/themes/custom/gsmamarketplace/font/UniversNextforHSBCW29-Light.woff2")
> format("woff2");
> }
>
>
> </div>
> <div class="error-content">
> <h1>500 <br> Internal server problem</h1>
> <p>Sorry, An error occurred and your request
> couldn't be completed. <a href="/">Return to the home
> page</a></p>
> </div>
> </div>
> </div>
> </body>
> </html>
>
> ############################################################################################################
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
>
> Best Regards,
>
> Kaushal
>
> _______________________________________________
> nginx mailing list --nginx at nginx.org
> To unsubscribe send an email tonginx-leave at nginx.org
--
Dan G. Switzer, II
Giva, Inc.
Email:dan.switzer at givainc.com
Web Site:http://www.givainc.com
See Our Customer Successes
http://www.givainc.com/customers-casestudies.htm
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221107/af76f864/attachment.htm>
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.
>
> location /api/v1/* {
> internal;
> add_header 'Content-Type' 'application/json charset=UTF-8';
>
> error_page 502 '{"error": {"status_code": 502,"status": "Bad
> Gateway"}}';
> }
>
> But whenever I try to send a request to /api/v1/users via curl I get the
> HTML source code in response instead of JSON response.
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
First of all, the "/api/v1/*" does not look like a valid prefix.
Note that "*" is not special in prefix locations, so you need just
"/api/v1/" to match relevant requests. See
http://nginx.org/r/location for details.
Further, trying to overwrite the Content-Type returned with the
add_header directive will fail, as nginx will still send the
Content-Type as set by the "types" and "default_type" directive.
See http://nginx.org/r/types for details. To set charset you can
use the "charset" directive, see http://nginx.org/r/charset.
Additionally, the "error_page" directive does not accept strings.
If you want to return a string directly from nginx in case of an error,
you can use error_page with an internal URI, and then use the
"return" directive to return the text. See
http://nginx.org/r/error_page and http://nginx.org/r/return for
details.
And, as already pointed out in another response, the "internal"
directive implies that the location won't be accessible from the
outside, so you have to remove it. See
http://nginx.org/r/internal for details.
Further, your location does not contain actual proxying - so you
probably want to add some, or all matched requests will be
considered requests to static files.
Summing the above, valid configuration will look like:
location /api/v1/ {
error_page 502 /error502;
proxy_pass ...
}
location = /error502 {
default_type text/json;
charset UTF-8;
charset_types text/json;
return 200 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
}
It might be a good idea to start with reading some introductory
articles at http://nginx.org/en/docs/, notably:
Beginner’s Guide
http://nginx.org/en/docs/beginners_guide.html
and
How nginx processes a request
http://nginx.org/en/docs/http/request_processing.html
Hope this helps.
--
Maxim Dounin
http://mdounin.ru/
On Tue, Nov 8, 2022 at 11:20 AM Maxim Dounin <mdounin at mdounin.ru> 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 i hit http://mydomain.com/api/v1/* instead of the html
> > response.
> >
> > location /api/v1/* {
> > internal;
> > add_header 'Content-Type' 'application/json charset=UTF-8';
> >
> > error_page 502 '{"error": {"status_code": 502,"status": "Bad
> > Gateway"}}';
> > }
> >
> > But whenever I try to send a request to /api/v1/users via curl I get the
> > HTML source code in response instead of JSON response.
> >
> > Please guide me. Thanks in advance. I look forward to hearing from you.
>
> First of all, the "/api/v1/*" does not look like a valid prefix.
> Note that "*" is not special in prefix locations, so you need just
> "/api/v1/" to match relevant requests. See
> http://nginx.org/r/location for details.
>
> Further, trying to overwrite the Content-Type returned with the
> add_header directive will fail, as nginx will still send the
> Content-Type as set by the "types" and "default_type" directive.
> See http://nginx.org/r/types for details. To set charset you can
> use the "charset" directive, see http://nginx.org/r/charset.
>
> Additionally, the "error_page" directive does not accept strings.
> If you want to return a string directly from nginx in case of an error,
> you can use error_page with an internal URI, and then use the
> "return" directive to return the text. See
> http://nginx.org/r/error_page and http://nginx.org/r/return for
> details.
>
> And, as already pointed out in another response, the "internal"
> directive implies that the location won't be accessible from the
> outside, so you have to remove it. See
> http://nginx.org/r/internal for details.
>
> Further, your location does not contain actual proxying - so you
> probably want to add some, or all matched requests will be
> considered requests to static files.
>
> Summing the above, valid configuration will look like:
>
> location /api/v1/ {
> error_page 502 /error502;
> proxy_pass ...
> }
>
> location = /error502 {
> default_type text/json;
> charset UTF-8;
> charset_types text/json;
> return 200 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
> }
>
> It might be a good idea to start with reading some introductory
> articles at http://nginx.org/en/docs/, notably:
>
> Beginner’s Guide
> http://nginx.org/en/docs/beginners_guide.html
>
> and
>
> How nginx processes a request
> http://nginx.org/en/docs/http/request_processing.html
>
> Hope this helps.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list -- nginx at nginx.org
> To unsubscribe send an email to nginx-leave at nginx.org
Thanks Maxim for a detailed explanation and I am currently reading the
documentation.
I have a follow up question, when the user invokes ->
http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx Webserver
-> Drupal 9 Core CMS -> PHP-FPM backend server.
Nginx should present the below info on 500 ISE error conditions for /apis
and /apis/* The below message sends back the response to Nginx web server
to render it to the client browser instead of the /error-500.html file
contents.
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occured while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
I have the below settings in nginx conf file
error_page 500 /error-500.html;
location = /error-500.html {
root
/var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
}
error_page 503 /error-503.html;
location = /error-503.html {
root
/var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
}
I am trying to set the below location and try_files directive block in
nginx.conf file
location /apis {
try_files $uri $uri/ /path/to/api/handler; (This part is not
clear with me)
}
to send back the below response to the client browser instead of rendering
the /error-500.html file contents.
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occured while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
Please guide me. Thanks in advance. I look forward to hearing from you.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221108/92027e08/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 3646 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221108/92027e08/attachment.obj>
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 <http://mydomain.com/api/v1/*> -> Nginx Webserver
-> Drupal 9 Core CMS -> PHP-FPM backend server.
Nginx should present the below info on 500 ISE error conditions for /apis
and /apis/* The below message sends back the response to Nginx web server
to render it to the client browser instead of the /error-500.html file
contents.
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occured while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
I have the below settings in nginx conf file
error_page 500 /error-500.html;
location = /error-500.html {
root
/var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
}
error_page 503 /error-503.html;
location = /error-503.html {
root
/var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
}
I am trying to set the below location and try_files directive block in
nginx.conf file
location /apis {
try_files $uri $uri/ /path/to/api/handler; (This part is not
clear with me)
}
to send back the below response to the client browser instead of rendering
the /error-500.html file contents.
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occured while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
Please guide me. Thanks in advance. I look forward to hearing from you.
Best Regards,
Kaushal
On Tue, Nov 8, 2022 at 1:25 PM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
>
>
> On Tue, Nov 8, 2022 at 11:20 AM Maxim Dounin <mdounin at mdounin.ru> 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 i hit http://mydomain.com/api/v1/* instead of the html
>> > response.
>> >
>> > location /api/v1/* {
>> > internal;
>> > add_header 'Content-Type' 'application/json charset=UTF-8';
>> >
>> > error_page 502 '{"error": {"status_code": 502,"status": "Bad
>> > Gateway"}}';
>> > }
>> >
>> > But whenever I try to send a request to /api/v1/users via curl I get the
>> > HTML source code in response instead of JSON response.
>> >
>> > Please guide me. Thanks in advance. I look forward to hearing from you.
>>
>> First of all, the "/api/v1/*" does not look like a valid prefix.
>> Note that "*" is not special in prefix locations, so you need just
>> "/api/v1/" to match relevant requests. See
>> http://nginx.org/r/location for details.
>>
>> Further, trying to overwrite the Content-Type returned with the
>> add_header directive will fail, as nginx will still send the
>> Content-Type as set by the "types" and "default_type" directive.
>> See http://nginx.org/r/types for details. To set charset you can
>> use the "charset" directive, see http://nginx.org/r/charset.
>>
>> Additionally, the "error_page" directive does not accept strings.
>> If you want to return a string directly from nginx in case of an error,
>> you can use error_page with an internal URI, and then use the
>> "return" directive to return the text. See
>> http://nginx.org/r/error_page and http://nginx.org/r/return for
>> details.
>>
>> And, as already pointed out in another response, the "internal"
>> directive implies that the location won't be accessible from the
>> outside, so you have to remove it. See
>> http://nginx.org/r/internal for details.
>>
>> Further, your location does not contain actual proxying - so you
>> probably want to add some, or all matched requests will be
>> considered requests to static files.
>>
>> Summing the above, valid configuration will look like:
>>
>> location /api/v1/ {
>> error_page 502 /error502;
>> proxy_pass ...
>> }
>>
>> location = /error502 {
>> default_type text/json;
>> charset UTF-8;
>> charset_types text/json;
>> return 200 '{"error": {"status_code": 502,"status": "Bad Gateway"}}';
>> }
>>
>> It might be a good idea to start with reading some introductory
>> articles at http://nginx.org/en/docs/, notably:
>>
>> Beginner’s Guide
>> http://nginx.org/en/docs/beginners_guide.html
>>
>> and
>>
>> How nginx processes a request
>> http://nginx.org/en/docs/http/request_processing.html
>>
>> Hope this helps.
>>
>> --
>> Maxim Dounin
>> http://mdounin.ru/
>> _______________________________________________
>> nginx mailing list -- nginx at nginx.org
>> To unsubscribe send an email to nginx-leave at nginx.org
>
>
> Thanks Maxim for a detailed explanation and I am currently reading the
> documentation.
> I have a follow up question, when the user invokes ->
> http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx
> Webserver -> Drupal 9 Core CMS -> PHP-FPM backend server.
>
> Nginx should present the below info on 500 ISE error conditions for /apis
> and /apis/* The below message sends back the response to Nginx web server
> to render it to the client browser instead of the /error-500.html file
> contents.
>
> "type" => "/problems/API-saving-error",
> "title" => $this->t("Issue occured while saving the
> API."),
> "detail" => $this->t("There are some wrong inputs passed
> to DB which caused this issue."),
>
> I have the below settings in nginx conf file
>
> error_page 500 /error-500.html;
> location = /error-500.html {
> root
> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
> }
>
> error_page 503 /error-503.html;
> location = /error-503.html {
> root
> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
> }
>
> I am trying to set the below location and try_files directive block in
> nginx.conf file
> location /apis {
> try_files $uri $uri/ /path/to/api/handler; (This part is not
> clear with me)
> }
>
> to send back the below response to the client browser instead of rendering
> the /error-500.html file contents.
>
> "type" => "/problems/API-saving-error",
> "title" => $this->t("Issue occured while saving the
> API."),
> "detail" => $this->t("There are some wrong inputs passed
> to DB which caused this issue."),
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
>
> Best Regards,
>
> Kaushal
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221109/a889572f/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 3646 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221109/a889572f/attachment.obj>
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
exactly what you are asking.
Maybe it is also unclear to others? In that case,it may be useful if
you can simplify your example question?
> I have a follow up question, when the user invokes ->
> http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx Webserver
> -> Drupal 9 Core CMS -> PHP-FPM backend server.
>
> Nginx should present the below info on 500 ISE error conditions for /apis
> and /apis/* The below message sends back the response to Nginx web server
> to render it to the client browser instead of the /error-500.html file
> contents.
>
> "type" => "/problems/API-saving-error",
> "title" => $this->t("Issue occured while saving the
> API."),
> "detail" => $this->t("There are some wrong inputs passed
> to DB which caused this issue."),
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/example, maybe something else?)
For that one specific request, what do you want nginx to do with
it? (Maybe make a http request to the Drupal system? Or a fastcgi request
to the Drupal system? Or handle it internally withint nginx?)
For the response from that request, what do you want nginx to do with
it? (Send it to the user as-is? Mangle / modify it somehow? If so --
how? Change the http response code or headers? Change the response body?)
I suspect that if you can describe what exactly you want nginx to do,
someone will have a better chance of sharing how to configure nginx to
do that thing.
> I have the below settings in nginx conf file
>
> error_page 500 /error-500.html;
> location = /error-500.html {
> root
> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
> }
For example: the above stanza says "if nginx is going to
send a http 500 response, it should send the contents of the file
/var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html/error-500.html
as the response body", along with the http 500 response header.
If that is what you want nginx to do, the configuration is correct. If
it is not, it is not.
> I am trying to set the below location and try_files directive block in
> nginx.conf file
> location /apis {
> try_files $uri $uri/ /path/to/api/handler; (This part is not
> clear with me)
> }
And I can see what this nginx config will do; but I do not know what you
want it to do. If you can give the full details for one example request,
then maybe it will become clear to me. (And maybe others will be able
to help too, if they are similarly confused.)
Thanks,
f
--
Francis Daly francis at daoine.org
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 <francis at daoine.org> 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 me.
>
> You seem to be showing multiple different requests, so I'm not sure
> exactly what you are asking.
>
> Maybe it is also unclear to others? In that case,it may be useful if
> you can simplify your example question?
>
> > I have a follow up question, when the user invokes ->
> > http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx
> Webserver
> > -> Drupal 9 Core CMS -> PHP-FPM backend server.
> >
> > Nginx should present the below info on 500 ISE error conditions for /apis
> > and /apis/* The below message sends back the response to Nginx web server
> > to render it to the client browser instead of the /error-500.html file
> > contents.
> >
> > "type" => "/problems/API-saving-error",
> > "title" => $this->t("Issue occured while saving the
> > API."),
> > "detail" => $this->t("There are some wrong inputs
> passed
> > to DB which caused this issue."),
>
> 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/example, maybe something else?)
>
> For that one specific request, what do you want nginx to do with
> it? (Maybe make a http request to the Drupal system? Or a fastcgi request
> to the Drupal system? Or handle it internally withint nginx?)
>
> For the response from that request, what do you want nginx to do with
> it? (Send it to the user as-is? Mangle / modify it somehow? If so --
> how? Change the http response code or headers? Change the response body?)
>
>
> I suspect that if you can describe what exactly you want nginx to do,
> someone will have a better chance of sharing how to configure nginx to
> do that thing.
>
> > I have the below settings in nginx conf file
> >
> > error_page 500 /error-500.html;
> > location = /error-500.html {
> > root
> >
> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
> > }
>
> For example: the above stanza says "if nginx is going to
> send a http 500 response, it should send the contents of the file
>
> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html/error-500.html
> as the response body", along with the http 500 response header.
>
> If that is what you want nginx to do, the configuration is correct. If
> it is not, it is not.
>
> > I am trying to set the below location and try_files directive block in
> > nginx.conf file
> > location /apis {
> > try_files $uri $uri/ /path/to/api/handler; (This part is not
> > clear with me)
> > }
>
> And I can see what this nginx config will do; but I do not know what you
> want it to do. If you can give the full details for one example request,
> then maybe it will become clear to me. (And maybe others will be able
> to help too, if they are similarly confused.)
>
> Thanks,
>
> 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/20221111/c54700ac/attachment.htm>
> On Fri, Nov 11, 2022 at 2:38 PM Francis Daly <francis at daoine.org> 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 me.
>>
>> You seem to be showing multiple different requests, so I'm not sure
>> exactly what you are asking.
>>
>> Maybe it is also unclear to others? In that case,it may be useful if
>> you can simplify your example question?
>>
>> > I have a follow up question, when the user invokes ->
>> > http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx
>> Webserver
>> > -> Drupal 9 Core CMS -> PHP-FPM backend server.
>> >
>> > Nginx should present the below info on 500 ISE error conditions for
>> /apis
>> > and /apis/* The below message sends back the response to Nginx web
>> server
>> > to render it to the client browser instead of the /error-500.html file
>> > contents.
>> >
>> > "type" => "/problems/API-saving-error",
>> > "title" => $this->t("Issue occured while saving the
>> > API."),
>> > "detail" => $this->t("There are some wrong inputs
>> passed
>> > to DB which caused this issue."),
>>
>> 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/example, maybe something else?)
>>
>> For that one specific request, what do you want nginx to do with
>> it? (Maybe make a http request to the Drupal system? Or a fastcgi request
>> to the Drupal system? Or handle it internally withint nginx?)
>>
>> For the response from that request, what do you want nginx to do with
>> it? (Send it to the user as-is? Mangle / modify it somehow? If so --
>> how? Change the http response code or headers? Change the response body?)
>>
>>
>> I suspect that if you can describe what exactly you want nginx to do,
>> someone will have a better chance of sharing how to configure nginx to
>> do that thing.
>>
>> > I have the below settings in nginx conf file
>> >
>> > error_page 500 /error-500.html;
>> > location = /error-500.html {
>> > root
>> >
>> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
>> > }
>>
>> For example: the above stanza says "if nginx is going to
>> send a http 500 response, it should send the contents of the file
>>
>> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html/error-500.html
>> as the response body", along with the http 500 response header.
>>
>> If that is what you want nginx to do, the configuration is correct. If
>> it is not, it is not.
>>
>> > I am trying to set the below location and try_files directive block in
>> > nginx.conf file
>> > location /apis {
>> > try_files $uri $uri/ /path/to/api/handler; (This part is not
>> > clear with me)
>> > }
>>
>> And I can see what this nginx config will do; but I do not know what you
>> want it to do. If you can give the full details for one example request,
>> then maybe it will become clear to me. (And maybe others will be able
>> to help too, if they are similarly confused.)
>>
>> Thanks,
>>
>> 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
>
>
Hi,
We have a Drupal site and for this Drupal site we are showing customized
HTML pages if any 500 errors occurred in the site. This customized 500 html
error page is configured at Nginx server, so that whenever any 500 error
occurs on site, Nginx presents that HTML page.
Now , we don’t want that HTML error page for all the cases even if there
500 errors occurred, instead we need a JSON response. For example
https://mydrupalsite.com/apis and https://mydrupalsite.com/apis/uinque_id
for these two page hits, even if 500 error occurred we don’t want to show
the default HTML 500 error page which is configured at Nginx server level.
But Nginx should present the same HTML 500 error page for all other page
requests if 500 errors occurred while accessing those pages.
Question is can we do any configuration changes at Nginx , so that it will
not do anything even if 500 error occurred for that specific two types of
page request mentioned above while it will still consider other page
requests apart from these two for showing up the HTML error page as per the
configuration if 500 error occurred.
Problem that we are facing - We are handling the 500 error at code level in
Drupal end and we are sending JSON data, but that is not getting displayed
as Nginx taking the control of 500 error and it’s showing up the HTML error
page. We already verified that when we are removing that Nginx 500 error
page configuration, in that case we are getting JSON data that Drupal sent
for 500 errors.
So I think, if somehow we can pass the information to Nginx to not take any
action if 500 error occurred while hitting the
https://mydrupalsite.com/apis or https://mydrupalsite.com/apis/uinque_id
URLs then our job will done, because in that case whatever Drupal is
sending we will be able to see that if 500 error occurred. Please note that
for the URLhttps://mydrupalsite.com/apis/uinque_id , uinque_id is a
parameter and it can be changed.
I have attached the nginx.conf file for your reference.
Please guide me. Thanks in advance. I look forward to hearing from you.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221114/b8b5eb43/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 3646 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221114/b8b5eb43/attachment.obj>
On Mon, Nov 14, 2022 at 8:24 PM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
>
>
>> On Fri, Nov 11, 2022 at 2:38 PM Francis Daly <francis at daoine.org> 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 me.
>>>
>>> You seem to be showing multiple different requests, so I'm not sure
>>> exactly what you are asking.
>>>
>>> Maybe it is also unclear to others? In that case,it may be useful if
>>> you can simplify your example question?
>>>
>>> > I have a follow up question, when the user invokes ->
>>> > http://mydomain.com/apis <http://mydomain.com/api/v1/*> -> Nginx
>>> Webserver
>>> > -> Drupal 9 Core CMS -> PHP-FPM backend server.
>>> >
>>> > Nginx should present the below info on 500 ISE error conditions for
>>> /apis
>>> > and /apis/* The below message sends back the response to Nginx web
>>> server
>>> > to render it to the client browser instead of the /error-500.html file
>>> > contents.
>>> >
>>> > "type" => "/problems/API-saving-error",
>>> > "title" => $this->t("Issue occured while saving the
>>> > API."),
>>> > "detail" => $this->t("There are some wrong inputs
>>> passed
>>> > to DB which caused this issue."),
>>>
>>> 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/example, maybe something else?)
>>>
>>> For that one specific request, what do you want nginx to do with
>>> it? (Maybe make a http request to the Drupal system? Or a fastcgi request
>>> to the Drupal system? Or handle it internally withint nginx?)
>>>
>>> For the response from that request, what do you want nginx to do with
>>> it? (Send it to the user as-is? Mangle / modify it somehow? If so --
>>> how? Change the http response code or headers? Change the response body?)
>>>
>>>
>>> I suspect that if you can describe what exactly you want nginx to do,
>>> someone will have a better chance of sharing how to configure nginx to
>>> do that thing.
>>>
>>> > I have the below settings in nginx conf file
>>> >
>>> > error_page 500 /error-500.html;
>>> > location = /error-500.html {
>>> > root
>>> >
>>> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html;
>>> > }
>>>
>>> For example: the above stanza says "if nginx is going to
>>> send a http 500 response, it should send the contents of the file
>>>
>>> /var/www/html/gsmamarketplace/web/servererrorpages/error-pages-500-503/html/error-500.html
>>> as the response body", along with the http 500 response header.
>>>
>>> If that is what you want nginx to do, the configuration is correct. If
>>> it is not, it is not.
>>>
>>> > I am trying to set the below location and try_files directive block in
>>> > nginx.conf file
>>> > location /apis {
>>> > try_files $uri $uri/ /path/to/api/handler; (This part is
>>> not
>>> > clear with me)
>>> > }
>>>
>>> And I can see what this nginx config will do; but I do not know what you
>>> want it to do. If you can give the full details for one example request,
>>> then maybe it will become clear to me. (And maybe others will be able
>>> to help too, if they are similarly confused.)
>>>
>>> Thanks,
>>>
>>> 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
>>
>>
> Hi,
>
> We have a Drupal site and for this Drupal site we are showing customized
> HTML pages if any 500 errors occurred in the site. This customized 500 html
> error page is configured at Nginx server, so that whenever any 500 error
> occurs on site, Nginx presents that HTML page.
>
> Now , we don’t want that HTML error page for all the cases even if there
> 500 errors occurred, instead we need a JSON response. For example
> https://mydrupalsite.com/apis and https://mydrupalsite.com/apis/uinque_id
> for these two page hits, even if 500 error occurred we don’t want to show
> the default HTML 500 error page which is configured at Nginx server level.
> But Nginx should present the same HTML 500 error page for all other page
> requests if 500 errors occurred while accessing those pages.
>
> Question is can we do any configuration changes at Nginx , so that it will
> not do anything even if 500 error occurred for that specific two types of
> page request mentioned above while it will still consider other page
> requests apart from these two for showing up the HTML error page as per the
> configuration if 500 error occurred.
>
> Problem that we are facing - We are handling the 500 error at code level
> in Drupal end and we are sending JSON data, but that is not getting
> displayed as Nginx taking the control of 500 error and it’s showing up the
> HTML error page. We already verified that when we are removing that Nginx
> 500 error page configuration, in that case we are getting JSON data that
> Drupal sent for 500 errors.
>
> So I think, if somehow we can pass the information to Nginx to not take
> any action if 500 error occurred while hitting the
> https://mydrupalsite.com/apis or https://mydrupalsite.com/apis/uinque_id
> URLs then our job will done, because in that case whatever Drupal is
> sending we will be able to see that if 500 error occurred. Please note that
> for the URLhttps://mydrupalsite.com/apis/uinque_id , uinque_id is a
> parameter and it can be changed.
>
> I have attached the nginx.conf file for your reference.
>
> Please guide me. Thanks in advance. I look forward to hearing from you.
>
> Best Regards,
>
> Kaushal
>
Hi,
Checking in again if someone can help me with my earlier post to this
mailing list? Thanks in advance.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221116/3c450c92/attachment.htm>
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 processing with the error_page
directive [2].
References
1. https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
2. http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
Hope that helps.
--
Sergey A. Osokin
On Thu, Nov 17, 2022 at 3:13 AM Sergey A. Osokin <osa at freebsd.org.ru> 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 directive [1],
> it helps to intercept 300+ error codes and processing with the error_page
> directive [2].
>
> References
> 1.
> https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
> 2. http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
>
> Hope that helps.
>
> --
> Sergey A. Osokin
> _______________________________________________
> nginx mailing list -- nginx at nginx.org
> To unsubscribe send an email to nginx-leave at nginx.org
Thanks Sergey for the email and appreciate it. I will go through the link
below and keep you updated. Thanks in advance.
1.
https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_intercept_errors
2. http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221117/91bc908c/attachment.htm>
On Mon, Nov 14, 2022 at 08:24:15PM +0530, Kaushal Shriyan wrote:
> > On Fri, Nov 11, 2022 at 2:38 PM Francis Daly <francis at daoine.org> 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/example, maybe something else?)
> >>
> >> For that one specific request, what do you want nginx to do with
> >> it? (Maybe make a http request to the Drupal system? Or a fastcgi request
> >> to the Drupal system? Or handle it internally withint nginx?)
> >>
> >> For the response from that request, what do you want nginx to do with
> >> it? (Send it to the user as-is? Mangle / modify it somehow? If so --
> >> how? Change the http response code or headers? Change the response body?)
> So I think, if somehow we can pass the information to Nginx to not take any
> action if 500 error occurred while hitting the
> https://mydrupalsite.com/apis or https://mydrupalsite.com/apis/uinque_id
> URLs then our job will done, because in that case whatever Drupal is
> sending we will be able to see that if 500 error occurred.
Correct.
You will want a location{} to handle the "api" requests; and in that
location, do not have the inherited "error_page 500" directive take effect.
I think that you cannot "undo" an error_page directive from a previous
level, but you can set a "dummy" error_page directive which will have
the effect of overriding any values set at a previous level. So --
pick a http response code that you do not care about (e.g. 555) and set
error_page for that in this location.
>From your config, it looks like there are three forms of "non-api"
requests that matter:
* /one/file.html - which will return the local file
/var/www/html/gsmamarketplace/web/one/file.html
* /two/file.php - which will ask drupal to use the local file
/var/www/html/gsmamarketplace/web/two/file.php
* /three/not-a-file - which will ask drupal to use the local file
/var/www/html/gsmamarketplace/web/index.php
What forms of "api" request do you expect to receive? And what,
specifically, do you want nginx to do with each form?
That is -- do you expect "/apis/one/file.html", or "/apis/two/file.php",
or "/apis/three/not-a-file", or some of each, or something else?
When the request is for "/apis/unique_id", what file on the filesystem
do you want nginx to serve; or what file on the filesystem do you want
nginx to ask drupal to use?
Cheers,
f
--
Francis Daly francis at daoine.org
On Thu, Nov 17, 2022 at 10:57 PM Francis Daly <francis at daoine.org> 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 <francis at daoine.org>
> 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/example, maybe something else?)
> > >>
> > >> For that one specific request, what do you want nginx to do with
> > >> it? (Maybe make a http request to the Drupal system? Or a fastcgi
> request
> > >> to the Drupal system? Or handle it internally withint nginx?)
> > >>
> > >> For the response from that request, what do you want nginx to do with
> > >> it? (Send it to the user as-is? Mangle / modify it somehow? If so --
> > >> how? Change the http response code or headers? Change the response
> body?)
>
> > So I think, if somehow we can pass the information to Nginx to not take
> any
> > action if 500 error occurred while hitting the
> > https://mydrupalsite.com/apis or
> https://mydrupalsite.com/apis/uinque_id
> > URLs then our job will done, because in that case whatever Drupal is
> > sending we will be able to see that if 500 error occurred.
>
> Correct.
>
> You will want a location{} to handle the "api" requests; and in that
> location, do not have the inherited "error_page 500" directive take effect.
>
> I think that you cannot "undo" an error_page directive from a previous
> level, but you can set a "dummy" error_page directive which will have
> the effect of overriding any values set at a previous level. So --
> pick a http response code that you do not care about (e.g. 555) and set
> error_page for that in this location.
>
>
> From your config, it looks like there are three forms of "non-api"
> requests that matter:
>
> * /one/file.html - which will return the local file
> /var/www/html/gsmamarketplace/web/one/file.html
>
> * /two/file.php - which will ask drupal to use the local file
> /var/www/html/gsmamarketplace/web/two/file.php
>
> * /three/not-a-file - which will ask drupal to use the local file
> /var/www/html/gsmamarketplace/web/index.php
>
>
> What forms of "api" request do you expect to receive? And what,
> specifically, do you want nginx to do with each form?
>
> That is -- do you expect "/apis/one/file.html", or "/apis/two/file.php",
> or "/apis/three/not-a-file", or some of each, or something else?
>
> When the request is for "/apis/unique_id", what file on the filesystem
> do you want nginx to serve; or what file on the filesystem do you want
> nginx to ask drupal to use?
>
> Cheers,
>
> 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
Thanks Francis for the detailed explanation.
Overriding the nginx 500 error message will not be a solution for us as we
are handling 500 errors in Drupal codebase, and 500 errors can occur in any
file of the codebase, at code level we are handling that and sending the
json response. So incase of, ' /apis ' call or .'apis/unique_id' call if
nginx web server does nothing, then by default the JSON response whatever
Drupal CMS (https://www.drupal.org/) sends will be displayed to the user
and this will solve our problem.
We can not have a dedicated page (either php or html) to display the
response as 500 error messages can occur from any random file of the
codebase. Whenever the 500 error occurs, Drupal CMS (https://www.drupal.org/)
will return a JSON response and that JSON response content can be different
based on the cause of the issue.
For example https://mydrupalsite.com/apis and
https://mydrupalsite.com/apis/uinque_id for these two page hits, even if
500 error occurred we do not want nginx to show the default HTML 500 error
page. In short we want nginx webserver to do nothing and not consider these
two pages while showing 500 errors.
Please let me know if you need any additional information and I look
forward to hearing from you. Thanks in advance.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221118/2c305323/attachment.htm>
On Fri, Nov 18, 2022 at 07:07:41PM +0530, Kaushal Shriyan wrote:
> On Thu, Nov 17, 2022 at 10:57 PM Francis Daly <francis at daoine.org> 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", what file on the filesystem
do you want nginx to ask drupal to use?
Thanks,
f
--
Francis Daly francis at daoine.org
On Fri, Nov 18, 2022 at 9:37 PM Francis Daly <francis at daoine.org> 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 <francis at daoine.org>
> 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", what file on the filesystem
> do you want nginx to ask drupal to use?
>
>
Thanks Francis for your email response. Let me explain with two different
scenarios :-
*Scenario 1 *
500 errors occurred in any random page of the site for example -
https://mydrupalsite.com/randompath , in that case we want Nginx to provide
an HTML error page. And this is working as we have set up a custom HTML
page and configured Nginx 500 error to point to that HTML page. We don't
have any issue here
*Scenario 2 *
500 error occurred when the user tried to access the page -
https://mydrupalsite.com/apis or https://mydrupalsite.com/apis/unique_id .
Here we want a json response that Drupal is sending. Now we can't say what
specific file Nginx should use in this case to display the JSON response.
As when a user is trying to access these pages , in the backend , to serve
this request Drupal is processing N number of files, now among those files
in any file that 500 exceptions can occur. At code level we are just
handling that and sending JSON responses. Like below.
try{
$node_new->save();
}
catch(\Exception $e) {
$output = [
"type" => "/problems/API-saving-error",
"title" => $this->t("Issue occurred while saving the
API."),
"detail" => $this->t("There are some wrong inputs passed
to DB which caused this issue."),
];
return new JsonResponse($output, 500);
}
So here you can see that we handled and sent the JSON response , now we
can't tell Nginx which file we want to present , as the JSON response can
come from any file where 500 exceptions are handled. (edited)
And moreover the content of the JSON response also varies based on the
reason behind that 500 exception, as we try to give relevant messages to
the user , so if 500 errors occurred in any other php file the JSON
response content can be different.
So we want Nginx to display this JSON response whatever Drupal is sending
instead presenting the default HTML page which is configured for 500 error
So , it's not like that we need to tell Nginx what file of the filesystem
Nginx can use to display 500 error for https://mydrupalsite.com/apis or
https://mydrupalsite.com/apis/unique_id, rather we want Nginx to display
whatever Drupal is sending. And it can be easily achieved if we don't
configure 500 error pages at Nginx , in that case whatever Drupal is ending
that only will be displayed. Problem is that we have to keep that 500 error
page configuration at Nginx and at the same Nginx should not use that error
page for these two types of URLs- https://mydrupalsite.com/apis or
https://mydrupalsite.com/apis/unique_id
Please let me know if you need any additional information and I look
forward to hearing from you. Thanks in advance.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221118/d1b24adc/attachment.htm>
On Fri, Nov 18, 2022 at 11:10:20PM +0530, Kaushal Shriyan wrote:
> On Fri, Nov 18, 2022 at 9:37 PM Francis Daly <francis at daoine.org> 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,
apart from the actual specific url patterns that you are using.
I suspect that I am being unclear in the question that I am asking.
Do you actually make an api request for exactly
https://mydrupalsite.com/apis/unique_id? If so, what response do you get?
And if you do not make an api request for exactly that url, can you show
any one url that you do use when making an api request?
What you will eventually want to add to your nginx config is something
like
location ^~ /apis/ {
error_page 555 /dummyfile;
fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_param SCRIPT_FILENAME something;
}
but I am unable to guess what the "something" should be. Maybe it should
always be "$document_root/index.php". And maybe different or other config
is needed as well.
f
--
Francis Daly francis at daoine.org
On Sat, Nov 19, 2022 at 12:02 AM Francis Daly <francis at daoine.org> 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 <francis at daoine.org> 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,
> apart from the actual specific url patterns that you are using.
>
> I suspect that I am being unclear in the question that I am asking.
>
> Do you actually make an api request for exactly
> https://mydrupalsite.com/apis/unique_id? If so, what response do you get?
>
> And if you do not make an api request for exactly that url, can you show
> any one url that you do use when making an api request?
>
> What you will eventually want to add to your nginx config is something
> like
>
> location ^~ /apis/ {
> error_page 555 /dummyfile;
> fastcgi_pass 127.0.0.1:9000;
> include fastcgi.conf;
> fastcgi_param SCRIPT_FILENAME something;
> }
>
> but I am unable to guess what the "something" should be. Maybe it should
> always be "$document_root/index.php". And maybe different or other config
> is needed as well.
>
>
>
Hi Francis,
Yes we do api calls for those endpoints , for example - for this URL
https://mydrupalsite.com/apis, we have defined an API at Drupal end, and on
successful it return json response like below.
{
"message": "API created successfully",
"uuid": "9891655f-8174-4099-a471-321bee01fafd",
"apiName": "sanity4 Automation_Payments_API_02_10_2022",
"gbgf": "Wealth and Personal Banking (WPB)",
"apiVersion": "1.0.0"
}
And for https://mydrupalsite.com/apis/unique_id also we have a specific API
call , on success which returns a JSON response like below.
{
"message": "API updated successfully",
"uuid": "9891655f-8174-4099-a471-321bee01fafd",
"apiName": "TEST3TMETA-rbwm-200-sa-get-message-details-updated",
"gbgf": "RBWM",
"apiVersion": "1.0.0"
}
On 500 errors also we are handling at Drupal and sending JSON responses to
specify the details about errors.
Please let me know if you need any additional information and I look
forward to hearing from you. Thanks in advance.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20221119/0b552df8/attachment.htm>
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