Skip to content

Instantly share code, notes, and snippets.

@mjallday
Last active December 25, 2015 07:19
Show Gist options
  • Save mjallday/6938237 to your computer and use it in GitHub Desktop.
Save mjallday/6938237 to your computer and use it in GitHub Desktop.
import SimpleHTTPServer
import SocketServer
PORT = 8000
class Server(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
headers = self.headers.dict
# curl http://127.0.0.1:8000 -u username:password
if self.headers.dict.get('authorization') != 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=':
self.send_response(401)
else:
self.send_response(200)
def serve_forever(port):
httpd = SocketServer.TCPServer(('', port), Server)
httpd.serve_forever()
if __name__ == "__main__":
serve_forever(8000)

ngx_http_auth_request_module

nginx.conf

location /private/ {
    auth_request /auth;
    ...
}

location = /auth {
    proxy_pass ...
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment