在Django的mod_wsgi的静态文件 [英] static file with mod_wsgi in django
问题描述
我已经搜查了很多,但我仍然对静态文件(CSS,图像,...)我的Django网站的一个问题。
I've searched a lot but I still have a problem with the static files (css, image,...) with my django website.
我使用mod_wsgi的上的archlinux 64位阿帕奇
I'm using mod_wsgi with apache on archlinux 64bits
我在我的http.conf补充吧:
I've added it in my http.conf :
LoadModule wsgi_module modules/mod_wsgi.so
<VirtualHost *:80>
WSGIDaemonProcess mart.localhost user=mart group=users processes=2 threads=25
WSGIProcessGroup mart.localhost
LogLevel debug
Alias /media /home/mart/programmation/python/django/martfiles/media/
<Directory /home/mart/programmation/python/django/martfiles/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi
</VirtualHost>
我试图用django.wsgi在我家的文件夹,但它不工作(许可被拒绝访问/
)(奇怪的是它的工作原理,如果我使用测试这里脚本给)
I tried to use the django.wsgi in my home folder but it doesn't work (permission denied to access /
) (strangely it works if I use the test script given here)
所有的目录和内容(Apache的文件夹,WSGI脚本,martfiles)具有的权限 775根:devusers
同组devusers,包括我的用户,HTTP和根
all the directories and content (apache folder, wsgi-script, martfiles) have the permission 775 root:devusers
with the group devusers including my user, http and root
在我的模板base.html文件,我称之为CSS是这样的:
in my template base.html, I call the css this way :
<html> <head>
<link rel="stylesheet" href="/media/css/style.css" />
和在/var/log/http/error.log误差
and the error in /var/log/http/error.log
[Sat Jan 16 13:22:21 2010] [error] [client 127.0.0.1] (13)Permission denied: access to /media/css/style.css denied, referer: http://localhost/
[Sat Jan 16 13:22:21 2010] [info] mod_wsgi (pid=14783): Attach interpreter ''
/srv/http/wsgi-script/django.wsgi
/home/.../martfiles/settings.py
感谢您
修改:我precise我的Django的网站工作正常(除了会议,但我不认为这是相关的),所以我不知道它是关系到django.wsgi文件(也许我错了),但什么是肯定的是,我应该能够使用django.wsgi从Apache文件夹之外
edit : I precise that my django website is working fine (except the sessions but I don't think it's related) so I'm not sure it's related to the django.wsgi file (maybe I'm wrong) but what is sure is that I should be able to use the django.wsgi from outside the apache folder
如果我换行别名/媒体/家庭/超市/ programmation / Python的/ Django的/ martfiles /媒体/
与别名/媒体/ SRV / HTTP /媒体/
并给出正确的权限,它的工作原理。但我不想(也不应该)把我所有的媒体在Apache的文件夹
if I change the line Alias /media /home/mart/programmation/python/django/martfiles/media/
with Alias /media /srv/http/media/
and gives the right permissions, it works. But I don't want (and shouldn't) to put all my media in the apache folder
推荐答案
这是不够的只是目录的/ home /超市/ programmation / Python的/ Django的/ martfiles /媒体'包含静态文件是可读和可搜索。运行Apache的用户必须具有读取和潜在的搜索访问到它所有的父目录备份到根目录下。由于在许多系统上的主目录是RWX ------'这会否认Apache访问不论Apache配置拒绝/允许指令。
It is not sufficient for just the directory '/home/mart/programmation/python/django/martfiles/media' containing static files to be readable and searchable. The user that Apache runs as must have read and potentially search access, to all parent directories of it back up to root directory. Since home directories on many systems are 'rwx------' this would deny Apache access irrespective of the Deny/Allow directives in Apache configuration.
建议您将Django项目和静态文件你家的帐户之外的某处,放松文件系统权限是必要的。
Suggest you place the Django project and static files outside of your home account somewhere and relax the file system permissions as necessary.
这篇关于在Django的mod_wsgi的静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!