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
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.
Your django.wsgi
file,
WSGIScriptAlias / /srv/http/wsgi-scripts/django.wsgi
is outside of the <Directory>
defined by:
<Directory /home/mart/programmation/python/django/martfiles/>
Try adding this to httpd.conf
:
<Directory /srv/http/wsgi-scripts/>
Order allow,deny
Allow from all
</Directory>
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:
<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>
So, if your dhango.wsgi is defined in a place set as accessible by a <Directory>
directive, you could also sudo 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...
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 adding NameVirtualHost *:80
before the virtual host definition.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.