[英]static file with mod_wsgi in django
我搜索了很多,但我的django网站仍然存在静态文件(css,image,...)的问题。
我在archlinux 64bits上使用带有apache的mod_wsgi
我在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,但它不起作用( permission denied to access /
)(奇怪的是,如果我使用这里给出的测试脚本,它可以工作)
所有的目录和内容(apache文件夹,wsgi-script,martfiles)都拥有权限775 root:devusers
和group devusers,包括我的用户,http和root
在我的模板base.html中,我用这种方式调用css:
<html> <head>
<link rel="stylesheet" href="/media/css/style.css" />
以及/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
谢谢
编辑 :我确定我的django网站工作正常(除了会话,但我不认为它是相关的)所以我不确定它与django.wsgi文件有关(也许我错了)但是肯定的是我应该能够从apache文件夹外部使用django.wsgi
如果我用Alias /media /srv/http/media/
更改Alias /media /home/mart/programmation/python/django/martfiles/media/
Alias /media /srv/http/media/
并给出正确的权限,它就可以了。 但我不希望(也不应该)将我的所有媒体放在apache文件夹中
仅包含静态文件的目录'/ home / mart / programmation / python / django / martfiles / media'是可读和可搜索的。 Apache运行的用户必须具有读取和潜在搜索访问权限,并将其备份到根目录的所有父目录。 由于许多系统上的主目录都是'rwx ------',因此无论Apache配置中的Deny / Allow指令如何,都会拒绝Apache访问。
建议您将Django项目和静态文件放在家庭帐户之外,并根据需要放宽文件系统权限。
你的django.wsgi
文件,
WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi
在<Directory>
定义:
<Directory /home/mart/programmation/python/django/martfiles/>
尝试将其添加到httpd.conf
:
<Directory /srv/http/wsgi-scripts/>
Order allow,deny
Allow from all
</Directory>
或者,将你的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>
因此,如果你的dhango.wsgi是在一个设置为可由<Directory>
指令访问的地方定义的,你也可以sudo su httpd
如果那是在你的系统上运行apache的用户,只是尝试读取css文件,看看如果apache可以真正访问它们......
这似乎是我的应用程序,除了我没有在http.conf中看到NameVirtualHost
指令,如果你想设置虚拟服务器是必需的。 您可以尝试在虚拟主机定义之前添加NameVirtualHost *:80
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.