static file with mod_wsgi in django

江枫思渺然 提交于 2019-11-30 05:23:48

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!