django 中带有 mod_wsgi 的静态文件 [英] static file with mod_wsgi in django

查看:21
本文介绍了django 中带有 mod_wsgi 的静态文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了很多,但我的 django 网站的静态文件(css、图像等)仍然有问题.

I've searched a lot but I still have a problem with the static files (css, image,...) with my django website.

我在 archlinux 64bits 上使用 mod_wsgi 和 apache

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-script、martfiles)都具有权限 775 root:devusers 与组 devusers 包括我的用户、http 和 root

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 ''

/etc/httpd/conf/http.conf

/srv/http/wsgi-script/django.wsgi

/home/.../martfiles/settings.py

谢谢

edit :我确定我的 django 网站运行良好(除了会话,但我认为它不相关)所以我不确定它是否与 django.wsgi 文件相关(也许我错了)但可以肯定的是,我应该能够从 apache 文件夹之外使用 django.wsgi

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

如果我将行 Alias/media/home/mart/programmation/python/django/martfiles/media/ 更改为 Alias/media/srv/http/media/> 并给予正确的权限,它的工作原理.但我不想(也不应该)把我所有的媒体都放在 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/mart/programmation/python/django/martfiles/media' 可读和可搜索是不够的.Apache 运行的用户必须具有读取和潜在搜索访问权限,将其所有父目录备份到根目录.由于许多系统上的主目录都是rwx------",因此无论 Apache 配置中的 Deny/Allow 指令如何,这都会拒绝 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屋!

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