1

I have set up an Apache server with WSGI/Django on it, and everything works fine -- html, css -- but when I try to request an image file, like png, it returns 403 Forbidden. The configuration is as follows:

sites-available/default

WSGIScriptAlias / /var/djangoblog/myDjangoBlog/wsgi.py

<Directory /var/djangoblog/myDjangoBlog>
<Files wsgi.py>
    Order deny,allow
    Allow from all
</Files>
</Directory>

Alias /robots.txt /var/www/robots.txt
Alias /favicon.ico /var/www/favicon.ico

Alias /static/ /var/djangoblog/static/
Alias /media/ /var/djangoblog/media/

<Directory /var/djangoblog/static>
    Order allow,deny
    Allow from all
</Directory>

<Directory /var/djangoblog/media>
    Order allow,deny
    Allow from all
</Directory>

I also tried to allow from all in httpd.conf, but no luck.

Could you please help me?

1 Answer 1

1

Most likely, this is a posix-permissions-issue or an selinux-context-issue. I would check to see that the png files in question are readable to your web-server user/group and are permissions 755. To check selinux contexts, try an "ls -RZl /var/djangoblog" and see that the contexts listed are the same for files that are served and files that are not.

After that, this is far less likely. Apache might be filtering the files, doubtful by default but in the huge open source wilderness where we don't know what distro you are on, it is a possibility. (debian, CentOS?)

Check httpd.conf and any conf.d/ like files/directories (anything that contains apache directives) especially for a line such as <FilesMatch ".(gif|jpg|jpeg|png)$"> which could be matching and rejecting the requests for those png files. These apache global files might be overaliasing the sites-enabled/default instance also, if they incidentally contain any /media/ // aliases.

1
  • Thanks, I figured it out. As you said, it was a permission issue. The file I tried to serve was marked no access to anybody else besides me and root.
    – FLamparski
    May 18, 2012 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.