使用 mod_wsgi 和 Django 提供静态文件
我有一个使用 mod_python 的 django 应用程序,这是相当典型的配置,除了媒体文件由文档根目录中的(我知道,不推荐)“media”目录提供服务。 我想测试并可能使用 mod_wsgi 进行部署,但我不知道如何创建一些简单的东西来提供静态文件。 mod_python 允许使用 Apache 指令,例如:
<Location '/'>
SetHandler MyApplication.xyz.....
</Location>
<Location '/media'>
SetHandler None
</Location>
django 文档似乎指出上面的第二个块是为 mod_wsgi 生成类似异常的正确方法,但在我的测试中,root 以下的所有内容仍然被发送到 wsgi 应用程序。 有没有一种使用 mod_wsgi 设置静态媒体目录的好方法,或者出于令人信服的技术原因,我试图做的事情是故意不受支持的? 欢迎指出完全不同方法的答案。
I have a django application using mod_python, fairly typical configuration except that media files are being served by a (I know, not recommended) 'media' directory in the document root. I would like to test and maybe deploy with mod_wsgi but I cannot figure out how to create something simple to serve static files. mod_python allows the use of Apache directives like:
<Location '/'>
SetHandler MyApplication.xyz.....
</Location>
<Location '/media'>
SetHandler None
</Location>
The django docs seem to point to the second block above as the correct way to make a similar exception for mod_wsgi, but in my tests everything below root is still being sent to the wsgi app. Is there a good way set a static media directory with mod_wsgi, or is what I am trying to do intentionally unsupported for compelling technical reasons? Answers that point to entirely different approaches are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在同一台服务器上运行十多个 Django 站点,以下是我配置媒体 URL 的方法。
每个虚拟主机都有以下配置:
这样我就可以在一个文件中对媒体处理进行任何更改。
然后,我的 media.include 文件如下所示:
这对我来说非常有效,并从 YSlow (另请参阅 杰夫·阿特伍德 (Jeff Atwood) 在 YSlow 上)。
另请注意,对于根目录,我使用以下配置:
...应该位于配置文件中的 Alias /media 之后(因为 Apache 按顺序查看别名)
I run a a dozen or so Django sites on the same server and here's how I configure the media URL's.
Each VirtualHost has the following configuration:
This way I can make any changes to the media handling in one file.
Then, my media.include file looks like this:
This has worked very well for me, and gets an A grade from YSlow (also see Jeff Atwood on YSlow).
Also note, for the root dir I use the following configuration:
... which should be after the Alias /media in your configuration file (because Apache looks at the aliases in order)
mod_wsgi 文档解释了如何设置静态文件,这些文件出现在 WSGI 应用程序安装所在 URL 下方。 请参阅:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines #Hosting_Of_Static_Files
请注意,使用 WSGIScriptAlias 指令挂载 WSGI 应用程序时不需要“Options +ExecCGI”。 仅当使用 AddHandler 将应用程序挂载为资源时才需要“ExecCGI”选项。
The mod_wsgi documentation explains how to setup static files which appear at a URL underneath that which the WSGI application is mounted at. See:
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files
Note that 'Options +ExecCGI' is not need when using WSGIScriptAlias directive to mount the WSGI application. The 'ExecCGI' option is only required when using AddHandler to mount applications as resources.