Trigger alternate response based on file presence or other URL response

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Trigger alternate response based on file presence or other URL response

wld75
Hi.

I'll try to make this make sense. I have a few web applications that I can't
change. They are behind an nginx+ loadbalancer. I have separate database
state that indicates whether or not requests should be forwarded to the
upstream, or a status page should be returned.

There is a web service that I can invoke that gives me access to the
database state. I tried using that service as a health_check uri to change
the upstream to "failed", but that doesn't work as the uri is just a path
appended to the host+port.

I could have something monitoring the database state web service running on
the nginx server instance that could, for example, create a flag file on the
nginx server instance that could indicate to nginx how it should deal with
the requests, but I'm not sure if/how I could configure that in nginx.

Would anyone have any suggestions on how I can control how nginx responds
based on state that isn't the upstream?

Many thanks for your help.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281639,281639#msg-281639

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Trigger alternate response based on file presence or other URL response

wld75
So i can see that I can do something like the maintenance mode example,
e.g.

if (-f $document_root/under_maintenance.html) {
   return 503;
}

Wondering if there is a way to use the URL endpoint to check.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,281639,281640#msg-281640

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

RE: Trigger alternate response based on file presence or other URL response

Reinis Rozitis
> Wondering if there is a way to use the URL endpoint to check.

One way to do it would be with: http://nginx.org/en/docs/http/ngx_http_auth_request_module.html


You said you have nginx+ which has the ability to reconfigure the the backends on the fly: http://nginx.org/en/docs/http/ngx_http_upstream_conf_module.html

So your application which can read the state from the database could just set the upstream(s) as down so nginx won't forward any requests.


Another (more advanced) way would be to do it inside nginx with lua ( https://github.com/openresty/lua-nginx-module ) wich can connect directly to the database (mysql/pgsql etc) and decide what response to return. Then again it's more complicated.

rr

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx