views:

848

answers:

3

Hello,

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

/etc/httpd/conf/http.conf

/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

A: 

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.

abhaga
if I do that I've got one more error in the error.log : '[error] VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results'
Martin Trigaux
Sorry, it should have been `NameVirtualHost *:80`. Updated the answer.
abhaga
+1  A: 

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 [email protected]
    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...

Attila Oláh
if I put the django.wsgi in martfiles, I've an error 403 access denied ([error] [client 127.0.0.1] (13)Permission denied: access to / denied). if I add the <Directory /srv... it doesn't change anything ([error] [client 127.0.0.1] (13)Permission denied: access to /media/css/style.css denied, referer: http://localhost/).
Martin Trigaux
Try simply adding `DocumentRoot /home/mart/programmation/python/django/martfiles` inside the `<VirtualHost>` section.
Attila Oláh
+4  A: 

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.

Graham Dumpleton
that's why I gave the 775 permission with the group devusers containing my apache user (http). Where and which permission ? I'll try it
Martin Trigaux
I put my medias in /usr/share/django with just root privileges and it works ! Thanks a lot
Martin Trigaux
+1 for fixing my error. What are the security implications of setting home permissions to 755?
Noah