Hi Maxim,
I have tested using the attached nginx.conf file for your reference. I
tested using both scenarios.
When MySQL DB is down it works as expected.
{"errors": "MySQL DB Server is down"}
MySQL DB is up and running
It reports {"errors": "MySQL DB Server is down"} in spite of MySQL DB
server being fine.
Please suggest. Thanks in advance.
Best Regards,
Kaushal
On Thu, Dec 22, 2022 at 7:04 AM Maxim Dounin <mdounin at mdounin.ru> wrote:
> Hello!
>
> On Tue, Dec 20, 2022 at 11:44:05PM +0530, Kaushal Shriyan wrote:
>
> > On Sat, Dec 17, 2022 at 3:48 AM Maxim Dounin <mdounin at mdounin.ru> wrote:
> >
> > > On Fri, Dec 16, 2022 at 11:53:40PM +0530, Kaushal Shriyan wrote:
> > >
> > > > 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.
> > > >
> > > > fastcgi_intercept_errors off
> > > > proxy_intercept_errors off
> > > >
> > > > User -> Nginx -> php-fpm -> MySQL DB.
> > > >
> > > > For example if the php-fpm upstream server is down then nginx should
> > > render
> > > > 502 bad gateway
> > > > if MySQL DB service is down then nginx should
> render
> > > > 500 ISE.
> > > >
> > > > 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.
> > >
> > > Not sure I understand what are you asking about.
> > >
> > > With fastcgi_intercept_errors turned off (the default) nginx does
> > > not intercept any of the errors returned by php-fpm.
> > >
> > > That is, when MySQL is down and php-fpm returns 500 (Internal
> > > Server Error), it is returned directory to the client. When
> > > php-fpm is down, nginx generates 502 (Bad Gateway) itself and
> > > returns it to the client.
> > >
> > >
> > Hi Maxim,
> >
> > Apologies for the delay in responding. I am still not able to get it. The
> > below settings will be hardcoded in nginx.conf. Is there a way to
> > dynamically render the different errors to the client when the client
> hits
> > http://mydomain.com/apis
> >
> > error_page 502 /502.json;
> >
> > location = /502.json {
> > return 200 '{"errors": {"status_code": 502, "status": "php-fpm
> > server is down"}}';
> > }
> >
> > Please guide me. Thanks in advance.
>
> You can pass these error pages to a backend server by using
> proxy_pass or fastcgi_pass in the location, much like any other
> resource in nginx.
>
> Note though that in most cases it's a bad idea, at least unless
> you have a dedicated backend to generate error pages: if a request
> to an upstream server failed, there is a good chance that another
> request to generate an error page will fail as well.
>
> As such, it is usually recommended to keep error pages served by
> nginx itself, either as static files, or directly returned with
> "return".
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230104/98c0276b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: nginxtest.conf
Type: application/octet-stream
Size: 7893 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230104/98c0276b/attachment-0001.obj>
Hi,
I will appreciate if someone can pitch in for my earlier post to this
mailing list. I have the below location block.
location /apis {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
fastcgi_intercept_errors off;
add_header "X-Debug-JSON-APIS" $upstream_http_content_type"abc" always;
default_type application/json;
return 500 '{"errors": "MySQL DB Server is down"}';
# if ($isdatatypejson = "no") {
# add_header 'Content-Type' 'application/json' always;
# add_header 'Content-Type-2'
$upstream_http_content_type$isdatatypejson"OK" always;
# return 502 '{"errors": {"status_code": 502,"status":
"php-fpm server is down"}}';
# }
When I hit http://mydomain.com/apis for conditions when MySQL DB is down. I
get the below output and it works as expected.
{"errors": "MySQL DB Server is down"}
When I hit http://mydomain.com/apis for conditions when MySQL DB is up and
running fine, I get the below output in spite of MySQL DB server being
fine.
{"errors": "MySQL DB Server is down"}
Ideally the application will be working as normal. Am I missing anything
in the nginx config? I have tested using the attached nginx.conf file for
your reference. Please suggest.
Thanks in advance.
Best Regards,
Kaushal
On Wed, Jan 4, 2023 at 10:53 PM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
> Hi Maxim,
>
> I have tested using the attached nginx.conf file for your reference. I
> tested using both scenarios.
>
> When MySQL DB is down it works as expected.
>
> {"errors": "MySQL DB Server is down"}
>
> MySQL DB is up and running
>
> It reports {"errors": "MySQL DB Server is down"} in spite of MySQL DB
> server being fine.
>
> Please suggest. Thanks in advance.
>
> Best Regards,
>
> Kaushal
>
>
> On Thu, Dec 22, 2022 at 7:04 AM Maxim Dounin <mdounin at mdounin.ru> wrote:
>
>> Hello!
>>
>> On Tue, Dec 20, 2022 at 11:44:05PM +0530, Kaushal Shriyan wrote:
>>
>> > On Sat, Dec 17, 2022 at 3:48 AM Maxim Dounin <mdounin at mdounin.ru>
>> wrote:
>> >
>> > > On Fri, Dec 16, 2022 at 11:53:40PM +0530, Kaushal Shriyan wrote:
>> > >
>> > > > 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.
>> > > >
>> > > > fastcgi_intercept_errors off
>> > > > proxy_intercept_errors off
>> > > >
>> > > > User -> Nginx -> php-fpm -> MySQL DB.
>> > > >
>> > > > For example if the php-fpm upstream server is down then nginx should
>> > > render
>> > > > 502 bad gateway
>> > > > if MySQL DB service is down then nginx should
>> render
>> > > > 500 ISE.
>> > > >
>> > > > 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.
>> > >
>> > > Not sure I understand what are you asking about.
>> > >
>> > > With fastcgi_intercept_errors turned off (the default) nginx does
>> > > not intercept any of the errors returned by php-fpm.
>> > >
>> > > That is, when MySQL is down and php-fpm returns 500 (Internal
>> > > Server Error), it is returned directory to the client. When
>> > > php-fpm is down, nginx generates 502 (Bad Gateway) itself and
>> > > returns it to the client.
>> > >
>> > >
>> > Hi Maxim,
>> >
>> > Apologies for the delay in responding. I am still not able to get it.
>> The
>> > below settings will be hardcoded in nginx.conf. Is there a way to
>> > dynamically render the different errors to the client when the client
>> hits
>> > http://mydomain.com/apis
>> >
>> > error_page 502 /502.json;
>> >
>> > location = /502.json {
>> > return 200 '{"errors": {"status_code": 502, "status": "php-fpm
>> > server is down"}}';
>> > }
>> >
>> > Please guide me. Thanks in advance.
>>
>> You can pass these error pages to a backend server by using
>> proxy_pass or fastcgi_pass in the location, much like any other
>> resource in nginx.
>>
>> Note though that in most cases it's a bad idea, at least unless
>> you have a dedicated backend to generate error pages: if a request
>> to an upstream server failed, there is a good chance that another
>> request to generate an error page will fail as well.
>>
>> As such, it is usually recommended to keep error pages served by
>> nginx itself, either as static files, or directly returned with
>> "return".
>>
>> --
>> Maxim Dounin
>> http://mdounin.ru/
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> https://mailman.nginx.org/mailman/listinfo/nginx
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230105/62a52bcf/attachment.htm>
On Thu, Jan 05, 2023 at 10:15:34PM +0530, Kaushal Shriyan wrote:
Hi there,
> When I hit http://mydomain.com/apis for conditions when MySQL DB is down. I
> get the below output and it works as expected.
>
> {"errors": "MySQL DB Server is down"}
>
> When I hit http://mydomain.com/apis for conditions when MySQL DB is up and
> running fine, I get the below output in spite of MySQL DB server being
> fine.
>
> {"errors": "MySQL DB Server is down"}
Your config is
location /apis {
return 500 '{"errors": "MySQL DB Server is down"}';
}
Whenever you make a request that is handled in that location{}, your
nginx will return that response.
It looks like your nginx is doing what it was told to do.
No part of your config indicates that nginx knows (or cares) whether
MySQL DB is up or down. Does something outside of nginx know that?
f
--
Francis Daly francis at daoine.org
On Sat, Jan 7, 2023 at 2:56 AM Francis Daly <francis at daoine.org> wrote:
> On Thu, Jan 05, 2023 at 10:15:34PM +0530, Kaushal Shriyan wrote:
>
> Hi there,
>
> > When I hit http://mydomain.com/apis for conditions when MySQL DB is
> down. I
> > get the below output and it works as expected.
> >
> > {"errors": "MySQL DB Server is down"}
> >
> > When I hit http://mydomain.com/apis for conditions when MySQL DB is up
> and
> > running fine, I get the below output in spite of MySQL DB server being
> > fine.
> >
> > {"errors": "MySQL DB Server is down"}
>
> Your config is
>
> location /apis {
> return 500 '{"errors": "MySQL DB Server is down"}';
> }
>
> Whenever you make a request that is handled in that location{}, your
> nginx will return that response.
>
> It looks like your nginx is doing what it was told to do.
>
> No part of your config indicates that nginx knows (or cares) whether
> MySQL DB is up or down. Does something outside of nginx know that?
>
> f
> --
> Francis Daly francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx
Thanks Francis for the detailed explanation. Is there a way to configure
Nginx for the below conditions?
When I hit http://mydomain.com/apis for conditions when MySQL DB is down. I
get the below output and it works as expected.
{"errors": "MySQL DB Server is down"}
When I hit http://mydomain.com/apis for conditions when MySQL DB is up and
running fine, I get the below output in spite of MySQL DB server being fine.
{"errors": "MySQL DB Server is down"}
Please suggest. Thanks in advance. I appreciate your help as always.
Best Regards,
Kaushal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230107/ac44b667/attachment.htm>
To query your MySql database, I propose you use a REST interface to
decouple it from your Front End.
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.)
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.
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.
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.
Let NGINX proxy all traffic between the REST Web Service and your Client.
Adjust cookie details as needed for the domain security sabdboxing.
On Fri, Jan 6, 2023, 9:58 PM Kaushal Shriyan <kaushalshriyan at gmail.com>
wrote:
>
>
> On Sat, Jan 7, 2023 at 2:56 AM Francis Daly <francis at daoine.org> wrote:
>
>> On Thu, Jan 05, 2023 at 10:15:34PM +0530, Kaushal Shriyan wrote:
>>
>> Hi there,
>>
>> > When I hit http://mydomain.com/apis for conditions when MySQL DB is
>> down. I
>> > get the below output and it works as expected.
>> >
>> > {"errors": "MySQL DB Server is down"}
>> >
>> > When I hit http://mydomain.com/apis for conditions when MySQL DB is up
>> and
>> > running fine, I get the below output in spite of MySQL DB server being
>> > fine.
>> >
>> > {"errors": "MySQL DB Server is down"}
>>
>> Your config is
>>
>> location /apis {
>> return 500 '{"errors": "MySQL DB Server is down"}';
>> }
>>
>> Whenever you make a request that is handled in that location{}, your
>> nginx will return that response.
>>
>> It looks like your nginx is doing what it was told to do.
>>
>> No part of your config indicates that nginx knows (or cares) whether
>> MySQL DB is up or down. Does something outside of nginx know that?
>>
>> f
>> --
>> Francis Daly francis at daoine.org
>> _______________________________________________
>> nginx mailing list
>> nginx at nginx.org
>> https://mailman.nginx.org/mailman/listinfo/nginx
>
>
>
> Thanks Francis for the detailed explanation. Is there a way to configure
> Nginx for the below conditions?
>
> When I hit http://mydomain.com/apis for conditions when MySQL DB is down.
> I get the below output and it works as expected.
>
> {"errors": "MySQL DB Server is down"}
>
> When I hit http://mydomain.com/apis for conditions when MySQL DB is up
> and running fine, I get the below output in spite of MySQL DB server being
> fine.
>
> {"errors": "MySQL DB Server is down"}
>
> Please suggest. Thanks in advance. I appreciate your help as always.
>
> Best Regards,
>
> Kaushal
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> https://mailman.nginx.org/mailman/listinfo/nginx
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20230107/f2f45320/attachment.htm>
On Sat, Jan 07, 2023 at 08:28:17AM +0530, Kaushal Shriyan wrote:
Hi there,
> Thanks Francis for the detailed explanation. Is there a way to configure
> Nginx for the below conditions?
I think, indirectly, yes.
If you want your nginx to react to some external status (e.g., the
up-or-down state of a MySQL DB), then you need to indicate how your
nginx will become aware of that status.
(For what it's worth: if there is nothing new in your system since
November / December, the suggestion remains "change your php to do this".)
f
--
Francis Daly francis at daoine.org