I want to encrypt a big static file on the server with Nginx when it's serving it. I want the encryption to be done with the public key sent in the request as a header and I want this endpoint to be accessible only to specific users (if someone finds the url, he should get access denied
if he's not allowed to access the file.) I want Nginx to serve these encrypted files with random access.
First question: Is it possible at all? (for the authorization part I'm all ears to know if there's any solution, my authentication and authorization is done in Django, session keys stored in postgre, but I have no idea if it's feasible to share it with nginx.) Can a lua plugin for nginx read session data from postgre (or redis) and do the authorization checks with good performance?
Second question: How?
One possible solution I though about is using different certificate files (generated with passwords by django) to serve files as https. But I have no idea if it's possible to use different certificate files dynamically generated based on URI or not and I have no idea if nginx can serve files with asymmetric encryption over https or if https protocol supports it at all even if client is a custom client other than normal browsers than can parse data whatever way needed.
Another possible solution is writing a Lua plugin for Nginx but that'd be extremely expensive solution for me considering my resources. But I'd be thankful if someone could tell me if it's possible at all even with a custom plugin or not.