Python django中带有mod_wsgi的静态文件

Python django中带有mod_wsgi的静态文件,python,django,apache,mod-wsgi,Python,Django,Apache,Mod Wsgi,我已经搜索了很多,但我仍然对django网站的静态文件(css、图像等)有问题 我在archlinux 64位上使用mod_wsgi和apache 我已将其添加到我的http.conf中: LoadModule wsgi_module modules/mod_wsgi.so <VirtualHost *:80> WSGIDaemonProcess mart.localhost user=mart group=users processes=2 threads=25

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

我在archlinux 64位上使用mod_wsgi和apache

我已将其添加到我的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>
以及/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 ''

多谢各位


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


如果我用
Alias/media/srv/http/media/
更改行
Alias/media/home/mart/programmation/python/django/martfiles/media/
,并赋予正确的权限,它就会工作。但是我不想(也不应该)将我的所有媒体都放在apache文件夹中,这似乎是我的应用程序所拥有的,只是我没有在http.conf中看到
NameVirtualHost
指令,这是设置虚拟服务器所必需的。您可以尝试在虚拟主机定义之前添加
NameVirtualHost*:80

您的
django.wsgi
文件

WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi
不在以下定义的
范围内:

<Directory /home/mart/programmation/python/django/martfiles/>
或者,将您的
django.wsgi
文件放在
/home/mart/programmation/python/django/martfiles/
中的某个位置。这应该行得通

编辑:好的,下面是一个在生产机器上工作的示例httpd.conf:

<VirtualHost *:80>
    # Admin email, Server Name (domain name) and any aliases
    ServerAdmin testing@example.de
    ServerName  www.example.de

    DocumentRoot /home/example/testing/parts/public

    Alias /media /home/example/testing/parts/public/media

    # WSGI Settings
    WSGIDaemonProcess example user=example group=example threads=25
    WSGIProcessGroup example
    WSGIScriptAlias / /home/example/testing/parts/public/django.wsgi

    <Directory "/home/example/testing/parts/public">
        # Allow Apache to follow links
        Options FollowSymLinks
        # Turn on the ability to use .htaccess files
        AllowOverride All
        # Controls who can get stuff from this directory
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

#管理员电子邮件、服务器名(域名)和任何别名
服务器管理员testing@example.de
服务器名www.example.de
文档根/主/示例/测试/零件/公共
别名/媒体/主页/示例/测试/部件/公共/媒体
#WSGI设置
WSGIDaemonProcess示例用户=示例组=示例线程=25
WSGIProcessGroup示例
WSGIScriptAlias//home/example/testing/parts/public/django.wsgi
#允许Apache跟踪链接
选项如下符号链接
#启用使用.htaccess文件的功能
允许超越所有
#控制谁可以从此目录获取内容
命令允许,拒绝
通融

因此,如果您的dhango.wsgi被定义在一个可以通过
指令访问的位置集上,您也可以
sudo su httpd
如果该用户在您的系统上运行apache,只需尝试读取css文件,要查看apache是否真的可以访问它们…

仅包含静态文件的目录“/home/mart/programmation/python/django/martfiles/media”是不够的。Apache运行的用户必须具有读取和潜在搜索权限,可以将其所有父目录备份到根目录。由于许多系统上的主目录是“rwx-----”,因此无论Apache配置中的deny/Allow指令如何,都会拒绝Apache访问


建议您将Django项目和静态文件放在主帐户之外的某个位置,并根据需要放宽文件系统权限。

如果我将Django.wsgi放在martfiles中,则会出现错误403拒绝访问([error][client 127.0.0.1](13)拒绝权限:访问/拒绝)。如果我添加了文件名,请尝试在
部分中添加
DocumentRoot/home/mart/programmation/python/django/martfiles
。您将单个
.htaccess
文件放在要配置的每个目录(服务目录)中。这就是为什么我对包含apache用户(http)的组devuser授予775权限。在哪里,哪种许可?我会试试的。我把我的媒体放在/usr/share/django中,只需要根权限就可以了!非常感谢+1修复我的错误。将主权限设置为755会带来什么安全影响?如果我这样做,我在error.log中还会出现一个错误:“[error]VirtualHost:80--不支持将*端口和非端口与NameVirtualHost地址混合,继续处理未定义的结果”“对不起,应该是
NameVirtualHost*:80
”。更新了答案。
<Directory /srv/http/wsgi-scripts/>
    Order allow,deny
    Allow from all
</Directory>
<VirtualHost *:80>
    # Admin email, Server Name (domain name) and any aliases
    ServerAdmin testing@example.de
    ServerName  www.example.de

    DocumentRoot /home/example/testing/parts/public

    Alias /media /home/example/testing/parts/public/media

    # WSGI Settings
    WSGIDaemonProcess example user=example group=example threads=25
    WSGIProcessGroup example
    WSGIScriptAlias / /home/example/testing/parts/public/django.wsgi

    <Directory "/home/example/testing/parts/public">
        # Allow Apache to follow links
        Options FollowSymLinks
        # Turn on the ability to use .htaccess files
        AllowOverride All
        # Controls who can get stuff from this directory
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>