Global auth_request for nginx

I have a server on which I run several subdomain sites with nginx

each subdomain has a server { ... } block in the configuration (in sites-enabled )

I want to add a dynamic global authentication server (another http site) that will check the requested subdomain and provide access or request user credentials

so the stream should be like

 request stie1.example.com ---> [auth check in database] / \ no yes / \ show username/pass form pass to site1.example.com 

I found the auth_request module, but the examples are only about the server context

and I want it in a top-level context ( http context) - where, of course, the location directive is not available

So basically what I want is a kind of global nginx middleware where I can run some code (like python) to check if the user has permission to view one of the hosted domains

any suggestions?

+8
nginx
source share
1 answer

Perhaps this will help if you provide the actual context for what exactly you want to do.

According to http://nginx.org/r/auth_request, the auth_request directive actually allows "two" levels of the location context - both in server and http contexts, so there is absolutely nothing to prevent you from including it globally for each individual server in your nginx instance.

Otherwise, if you want it to be included only in certain location directives and / or only certain server configurations, you can always use the include directive in any context, like http://nginx.org/r/include .

0
source share

All Articles