固定在一个Django网站静态媒体访问 [英] Secure static media access in a Django site

查看:171
本文介绍了固定在一个Django网站静态媒体访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个网站,注册用户可以上传文件。这些文件然后通过Apache服务。只有谁登录的用户应该能够访问这些文件。

我已经阅读href=\"http://docs.djangoproject.com/en/dev/howto/apache-auth/\">此但似乎人们必须登录两次使用不同类型的登陆框的同时访问网站和媒体,每一次。

有没有办法解决,还是有一些其他的方式来限制访问使用Django的认证数据库被Apache提供静态媒体?

我使用了mod_python。

修改:我怎么会读范大风的答案后解决这个<一个href=\"http://groups.google.com/group/django-users/browse%5Fthread/thread/b4ceae1956e003e5/\">this:


  1. 切换到WSGI。

  2. mod_xsendfile

  3. 感动了所有公众的媒体文件到/媒体/公共
  4. 的子文件夹
  5. 使用别名/媒体/公关/无功/网络公共文件夹添加访问... /媒体/公共

  6. 新增WSGIScriptAlias​​ /媒体/保护/ /var/www.../apache/django.wsgi(相同的处理,作为该网站的其余部分)

  7. 新增XSendFile开,XSendFileAllowAbove在

  8. 要Django的应用程序,我添加了/媒体/保护的URL配置它基本上做什么这里,只修改了我的身份验证系统。它处理的URL,如/媒体/保护/ GROUP_ID /文件,以便只有组的成员可以下载的文件。


解决方案

通常的方法做,这是一个特殊的头传回给Web服务器。

// WWW:

您可以用 nginx的使用X加速重定向在此的 Django的片段

对于Apache,应该是使用 mod_xsendfile 模块(<类似pretty href=\"http://groups.google.com/group/django-developers/browse%5Fthread/thread/297cbd7dec84ffb8\">discussion和范例上的Django用户邮件列表)。

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.

I have read this page but it seems that people would have to log in twice to access both the site and the media, each time using a different type of login box.

Is there a way around this or is there some other way to limit access to static media served by Apache using the Django authentication database?

I'm using mod_python.

EDIT: How I ended up solving this after reading Van Gale's answer and this:

  1. Switched to WSGI.
  2. Installed mod_xsendfile
  3. Moved all public media files into a subfolder in /media/public
  4. Added access to the public folder using an Alias /media/public /var/www.../media/public
  5. Added WSGIScriptAlias /media/protected/ /var/www.../apache/django.wsgi (same handler as for the rest of the site)
  6. Added XSendFile On and XSendFileAllowAbove On
  7. To the Django app I added an urlconf for /media/protected which does basically what's here, only modified for my authentication system. It handles urls such as /media/protected/GROUP_ID/file so that only members of the GROUP can download the files.

解决方案

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).

这篇关于固定在一个Django网站静态媒体访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆