<div dir="ltr">Hi Maxim,<br><div><br></div><div>I have a follow up question regarding the settings below in nginx.conf where the php-fpm upstream server is processing all php files for Drupal CMS. </div><div><br></div><div>fastcgi_intercept_errors off</div><div>proxy_intercept_errors off<br></div><div><br></div><div>User -> Nginx -> php-fpm -> MySQL DB. </div><div><br></div><div>For example if the php-fpm upstream server is down then nginx should render 502 bad gateway</div><div> if MySQL DB service is down then nginx should render 500 ISE.</div><div><br></div><div>Is there a way to render any of the messages or any custom messages to the User from the php-fpm upstream server that should be passed to a client without being intercepted by the Nginx web server. Any examples? I have attached the file for your reference. Please guide me. Thanks in advance. </div><div><br></div><div>Best Regards,</div><div><br></div><div>Kaushal</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 16, 2022 at 7:22 AM Kaushal Shriyan <<a href="mailto:kaushalshriyan@gmail.com">kaushalshriyan@gmail.com</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"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 16, 2022 at 1:38 AM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru" target="_blank">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 Thu, Dec 15, 2022 at 09:53:11PM +0530, Kaushal Shriyan wrote:<br>
<br>
> <br>
> I am running the nginx version: nginx/1.22 as a reverse proxy server on<br>
> CentOS Linux release 7.9.2009 (Core). When I hit <a href="http://mydomain.com/apis" rel="noreferrer" target="_blank">http://mydomain.com/apis</a> I<br>
> see the below message on the browser even if the upstream server php-fpm<br>
> server is up and running.<br>
> <br>
> *{"errors": {"status_code": 502,"status": "php-fpm server is down"}}*<br>
> <br>
> I have set the below in the nginx.conf file and attached the file for your<br>
> reference.<br>
> <br>
> if ($upstream_http_content_type = "") {<br>
> add_header 'Content-Type' 'application/json' always;<br>
> add_header 'Content-Type-3'<br>
> $upstream_http_content_type$isdatatypejson"OK" always;<br>
> return 502 '{"errors": {"status_code": 502,"status":<br>
> "php-fpm server is down"}}';<br>
> }<br>
<br>
The "if" directive makes it possible to conditionally select <br>
configuration to handle a request, and therefore can only use <br>
information available before the request is handled. In your <br>
case, before the request is sent to the upstream server. See <br>
<a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html" rel="noreferrer" target="_blank">http://nginx.org/en/docs/http/ngx_http_rewrite_module.html</a> for <br>
more details.<br>
<br>
As such, $upstream_http_content_type will be always empty, since <br>
there are no upstream response yet, and therefore the <br>
configuration will always return 502. This matches your <br>
observations.<br>
<br>
An obvious fix would be to remove the configuration chunk in <br>
question.<br>
<br>
Instead, you probably need something like:<br>
<br>
error_page 502 /502.json;<br>
<br>
location = /502.json {<br>
return 200 '{"errors": {"status_code": 502, "status": "php-fpm server is down"}}';<br>
}<br>
<br></blockquote><div><br></div><div><div class="gmail_quote">Thanks Maxim for the suggestion. I will try it out and keep you posted with the testing as it progresses. I am obliged to this mailing list. Thanks in advance. </div><div class="gmail_quote"><br></div><div class="gmail_quote">Best Regards,</div><div class="gmail_quote"><br></div><div class="gmail_quote">Kaushal</div></div></div></div>
</blockquote></div>