Trigger alternate response based on file presence or other URL response
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?
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.