4

I want to authorize access to directory /private using auth_request Nginx module .

In Nginx documentation , it seems I should do like bellow :

server {
        listen       80;
        server_name  localhost;

    location /private/{
            auth_request /auth;
    }

    location /auth {
        proxy_pass http://localhost:8080/;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Original-URI $request_uri;
    }
}

In my case http://localhost:8080/ is a python server, which should authenticate users against database. here is the python code :

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def post(self):
        print(str(self.request))
        raise tornado.web.HTTPError(403) # just test
    def get(self):
        print(str(self.request))
        raise tornado.web.HTTPError(401) # test also


application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8080)
    tornado.ioloop.IOLoop.current().start()

Now, when I visit http://localhost/private/ in the browser it prints :

pending on my code it returns

401 Authorization Required

Question : how do I request / receive username, and password data, so I could raise 401 exception or let the user pass?

0 Answers0