<div dir="ltr">Hi Maxim,<div><br></div><div>I have tested using the attached nginx.conf file for your reference. I tested using both scenarios. </div><div><br></div><div>When MySQL DB is down it works as expected.</div><div><br></div><div>{"errors": "MySQL DB Server is down"}<br></div><div><br></div><div>MySQL DB is up and running</div><div><br></div><div>It reports {"errors": "MySQL DB Server is down"} in spite of MySQL DB server being fine. </div><div><br></div><div>Please suggest. Thanks in advance.</div><div><br></div><div>Best Regards,</div><div><br></div><div>Kaushal</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Dec 22, 2022 at 7:04 AM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</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">Hello!<br>
<br>
On Tue, Dec 20, 2022 at 11:44:05PM +0530, Kaushal Shriyan wrote:<br>
<br>
> On Sat, Dec 17, 2022 at 3:48 AM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>> wrote:<br>
> <br>
> > On Fri, Dec 16, 2022 at 11:53:40PM +0530, Kaushal Shriyan wrote:<br>
> ><br>
> > > I have a follow up question regarding the settings below in nginx.conf<br>
> > > where the php-fpm upstream server is processing all php files for Drupal<br>
> > > CMS.<br>
> > ><br>
> > > fastcgi_intercept_errors off<br>
> > > proxy_intercept_errors off<br>
> > ><br>
> > > User -> Nginx -> php-fpm -> MySQL DB.<br>
> > ><br>
> > > For example if the php-fpm upstream server is down then nginx should<br>
> > render<br>
> > > 502 bad gateway<br>
> > > if MySQL DB service is down then nginx should render<br>
> > > 500 ISE.<br>
> > ><br>
> > > Is there a way to render any of the messages or any custom messages to<br>
> > the<br>
> > > User from the php-fpm upstream server that should be passed to a client<br>
> > > without being intercepted by the Nginx web server. Any examples? I have<br>
> > > attached the file for your reference. Please guide me. Thanks in advance.<br>
> ><br>
> > Not sure I understand what are you asking about.<br>
> ><br>
> > With fastcgi_intercept_errors turned off (the default) nginx does<br>
> > not intercept any of the errors returned by php-fpm.<br>
> ><br>
> > That is, when MySQL is down and php-fpm returns 500 (Internal<br>
> > Server Error), it is returned directory to the client. When<br>
> > php-fpm is down, nginx generates 502 (Bad Gateway) itself and<br>
> > returns it to the client.<br>
> ><br>
> ><br>
> Hi Maxim,<br>
> <br>
> Apologies for the delay in responding. I am still not able to get it. The<br>
> below settings will be hardcoded in nginx.conf. Is there a way to<br>
> dynamically render the different errors to the client when the client hits<br>
> <a href="http://mydomain.com/apis" rel="noreferrer" target="_blank">http://mydomain.com/apis</a><br>
> <br>
> error_page 502 /502.json;<br>
> <br>
> location = /502.json {<br>
> return 200 '{"errors": {"status_code": 502, "status": "php-fpm<br>
> server is down"}}';<br>
> }<br>
> <br>
> Please guide me. Thanks in advance.<br>
<br>
You can pass these error pages to a backend server by using <br>
proxy_pass or fastcgi_pass in the location, much like any other <br>
resource in nginx.<br>
<br>
Note though that in most cases it's a bad idea, at least unless <br>
you have a dedicated backend to generate error pages: if a request <br>
to an upstream server failed, there is a good chance that another <br>
request to generate an error page will fail as well.<br>
<br>
As such, it is usually recommended to keep error pages served by <br>
nginx itself, either as static files, or directly returned with <br>
"return".<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="https://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">https://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div>