django 中带有 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
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 但它不起作用(访问权限被拒绝/此处给出的测试脚本,它会起作用)
code>) (奇怪的是, 目录和内容(apache文件夹,wsgi-script,martfiles)具有权限775 root:devusers
,组devusers包括我的用户,
模板base.html中的http和root,我称之为css这样:
<html> <head>
<link rel="stylesheet" href="/media/css/style.css" />
中的错误
[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 ''
以及 /var/log/http/error.log /etc/httpd/conf/ http.conf
/srv/http/wsgi-script/django.wsgi
/home/.../martfiles/settings.py
谢谢
编辑 :我精确地说,我的 django 网站工作正常(除了会话,但我认为它不相关),所以我不确定它是否与 django.wsgi 文件相关(也许我错了),但可以肯定的是 我应该能够从 apache 文件夹外部使用 django.wsgi
如果我将行 Alias /media /home/mart/programmation/python/django/martfiles/media/
更改为 Alias, /media /srv/http/media/
并给出正确的权限,它可以工作。但我不想(也不应该)将所有媒体放在 apache 文件夹中
I've searched a lot but I still have a problem with the static files (css, image,...) with my django website.
I'm using mod_wsgi with apache on archlinux 64bits
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>
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)
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
in my template base.html, I call the css this way :
<html> <head>
<link rel="stylesheet" href="/media/css/style.css" />
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
thank you
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
仅包含静态文件的目录“/home/mart/programmation/python/django/martfiles/media”是可读和可搜索的。 Apache 运行的用户必须具有对其所有父目录(直至根目录)的读取和潜在搜索访问权限。由于许多系统上的主目录是“rwx------”,因此无论 Apache 配置中的拒绝/允许指令如何,这都会拒绝 Apache 访问。
建议您将 Django 项目和静态文件放置在您的家庭帐户之外的某个位置,并根据需要放宽文件系统权限。
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.
Suggest you place the Django project and static files outside of your home account somewhere and relax the file system permissions as necessary.
您的 django.wsgi 文件
位于由以下定义的
之外:尝试将其添加到
httpd.conf
中:或者,将您的
django.wsgi
文件位于/home/mart/programmation/python/django/martfiles/
内。那应该有效。编辑:好吧,这是一个在生产机器上运行的示例 httpd.conf:
因此,如果您的 dhango.wsgi 定义在可通过
指令访问的位置,您可以还有sudo su httpd
如果这是在您的系统上运行 apache 的用户,并且只需尝试读取 css 文件,看看 apache 是否真的可以访问它们...Your
django.wsgi
file,is outside of the
<Directory>
defined by:Try adding this to
httpd.conf
:Or, put your
django.wsgi
file somewhere inside/home/mart/programmation/python/django/martfiles/
. That should work.EDIT: alright, here's an example httpd.conf that is working on a production machine:
So, if your dhango.wsgi is defined in a place set as accessible by a
<Directory>
directive, you could alsosudo su httpd
if that's the user that runs apache on your system, and simply try to read the css files, to see if apache can really access them...这似乎就是我的应用程序所拥有的,只是我没有在 http.conf 中看到
NameVirtualHost
指令,如果您想设置虚拟服务器,则需要该指令。您可以尝试在虚拟主机定义之前添加NameVirtualHost *:80
。This seems to be what I have for my application except that I didn't see the
NameVirtualHost
directive in the http.conf which is required if you want to setup virtual servers. You can try addingNameVirtualHost *:80
before the virtual host definition.