<div dir="auto"><div dir="auto">To query your MySql database, I propose you use a REST interface to decouple it from your Front End.</div><div dir="auto"><br></div><div dir="auto">The REST interface should be a HTTP Web Service either self hosted or hosted by another Web Server locally on the NGINX Server.  (This allows NGINX to handle authentication and HTTPS encryption centrally.)</div><div dir="auto"><br></div><div dir="auto">As a result, use your REST Web Servive to also determine if tthe MySql DB s up or down when servicing the request and return a 200 message to NGINX indicating if there is an error in a JSON payload.</div><div dir="auto"><br></div><div dir="auto">I propose avoiding use of HTTP error codes yourself.  Let NGINX or the Web Server or the Client to deal with underlying network issues use status codes beyond 2000.  </div><div dir="auto"><br></div><div dir="auto">This also will guarantee your message will not be stripped and you can provide whatever level of detail needed for your client code or Front End to understand and handle. </div><div dir="auto"><br></div><div dir="auto"> Let NGINX proxy all traffic between the REST Web Service and your Client.  Adjust cookie details as needed for the domain security sabdboxing.</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 6, 2023, 9:58 PM Kaushal Shriyan <<a href="mailto:kaushalshriyan@gmail.com">kaushalshriyan@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jan 7, 2023 at 2:56 AM Francis Daly <<a href="mailto:francis@daoine.org" target="_blank" rel="noreferrer">francis@daoine.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jan 05, 2023 at 10:15:34PM +0530, Kaushal Shriyan wrote:<br>
<br>
Hi there,<br>
<br>
> When I hit <a href="http://mydomain.com/apis" rel="noreferrer noreferrer" target="_blank">http://mydomain.com/apis</a> for conditions when MySQL DB is down. I<br>
> get the below output and it works as expected.<br>
> <br>
> {"errors": "MySQL DB Server is down"}<br>
> <br>
> When I hit <a href="http://mydomain.com/apis" rel="noreferrer noreferrer" target="_blank">http://mydomain.com/apis</a> for conditions when MySQL DB is up and<br>
> running fine, I get the below output in spite of MySQL DB server being<br>
> fine.<br>
> <br>
> {"errors": "MySQL DB Server is down"}<br>
<br>
Your config is<br>
<br>
    location /apis {<br>
        return 500 '{"errors": "MySQL DB Server is down"}';<br>
    }<br>
<br>
Whenever you make a request that is handled in that location{}, your<br>
nginx will return that response.<br>
<br>
It looks like your nginx is doing what it was told to do.<br>
<br>
No part of your config indicates that nginx knows (or cares) whether<br>
MySQL DB is up or down. Does something outside of nginx know that?<br>
<br>
        f<br>
-- <br>
Francis Daly        <a href="mailto:francis@daoine.org" target="_blank" rel="noreferrer">francis@daoine.org</a><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank" rel="noreferrer">nginx@nginx.org</a><br>
<a href="https://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer noreferrer" target="_blank">https://mailman.nginx.org/mailman/listinfo/nginx</a></blockquote><div><br></div><div><br></div>Thanks Francis for the detailed explanation. Is there a way to configure Nginx for the below conditions?<br><br>When I hit <a href="http://mydomain.com/apis" target="_blank" rel="noreferrer">http://mydomain.com/apis</a> for conditions when MySQL DB is down. I get the below output and it works as expected.<br><br>{"errors": "MySQL DB Server is down"}<br><br>When I hit <a href="http://mydomain.com/apis" target="_blank" rel="noreferrer">http://mydomain.com/apis</a> for conditions when MySQL DB is up and running fine, I get the below output in spite of MySQL DB server being fine.<br><br>{"errors": "MySQL DB Server is down"}</div><div class="gmail_quote"> </div><div class="gmail_quote">Please suggest. Thanks in advance. I appreciate your help as always. <br></div><div class="gmail_quote"><span style="color:rgb(80,0,80)"><div><br></div><div>Best Regards,</div><div><br></div><div>Kaushal</div></span></div></div>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank" rel="noreferrer">nginx@nginx.org</a><br>
<a href="https://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer noreferrer" target="_blank">https://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div>