Secure static media access in a Django site

前端 未结 2 1495
遥遥无期
遥遥无期 2021-01-31 05:50

I\'m building a site where registered users can upload files. Those files are then served via Apache. Only users who are logged in should be able to access those files.

相关标签:
2条回答
  • 2021-01-31 06:18

    The usual way to do this is to pass back a special header to the web server.

    You can do it with nginx using x-accel-redirect as in this Django snippet.

    For Apache, it should be pretty similar using the mod_xsendfile module (discussion and examples on Django users mailing list).

    0 讨论(0)
  • 2021-01-31 06:41

    If you have freedom to switch from Apache to lighttpd, then the most straightforward solution would be to use mod_secdownload which would do exactly what you want, that is, provide application authentication while serving the actual files via web server.

    However if you are stuck with Apache, then I suggest mod_auth_token, here they mention PHP but you can generate the token in Python or any other language. Using mod_auth_token you will be able to generate the token in your application, and then have web server serve the static file utilizing that token.

    0 讨论(0)
提交回复
热议问题