Django apache mod_wsgi permission denied

2,732 views
Skip to first unread message

Loai Ghoraba

unread,
Nov 30, 2012, 7:00:55 PM11/30/12
to django...@googlegroups.com
Hi 

I have installed apache and mod_wsgi and my basic site *skeleton is running* on local host, but with NO static files loaded such as css, when I try to access a static file (e.g:http://localhost/static/css/base.css) it says that I don't have permission to access the file, same goes to media files 

I have followed the steps in the presentation slides http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-pycon-sydney-2010.pdf and made the directories accessible to others via chmod o+rx 
, my  httpd.conf part is :

WSGIScriptAlias / /home/loai/workspace/Faculty/Faculty/wsgi.py
WSGIPythonPath /home/loai/workspace/Faculty

Alias /media/ /home/loai/workspace/Faculty/Faculty/media
Alias /static/ /home/loai/workspace/Faculty/Faculty/static

<Directory /home/loai/workspace/Faculty/Faculty/static>
Order deny,allow
Allow from all
</Directory>

<Directory /home/loai/workspace/Faculty/Faculty/media>
Order deny,allow
Allow from all
</Directory>

Thanks

Chris Cogdon

unread,
Nov 30, 2012, 7:21:53 PM11/30/12
to django...@googlegroups.com
Make sure all the directories, from static leading all the way up to the root, are chmod a+x

Loai Ghoraba

unread,
Nov 30, 2012, 11:48:38 PM11/30/12
to django...@googlegroups.com
I have ran chmod o+rx on the root directory, isn't this enough (isn't chmod applied to all folders down recursively ?) ?

and I have checked the directories from the root down to static, all have the permission of drwxr-xr-x

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/L3Sm-aDXA_UJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Mike Dewhirst

unread,
Nov 30, 2012, 11:53:42 PM11/30/12
to django...@googlegroups.com
On 1/12/2012 3:48pm, Loai Ghoraba wrote:
> I have ran chmod o+rx on the root directory, isn't this enough (isn't
> chmod applied to all folders down recursively ?) ?

No. You need chmod -R o+rx


>
> and I have checked the directories from the root down to static, all
> have the permission of drwxr-xr-x
>
> On Sat, Dec 1, 2012 at 2:21 AM, Chris Cogdon <ch...@cogdon.org
> <mailto:ch...@cogdon.org>> wrote:
>
> Make sure all the directories, from static leading all the way up to
> the root, are chmod a+x
>
>
> On Friday, November 30, 2012 4:00:55 PM UTC-8, Loai Ghoraba wrote:
>
> Hi
>
> I have installed apache and mod_wsgi and my basic site *skeleton
> is running* on local host, but with NO static files loaded such
> as css, when I try to access a static file
> (e.g:http://localhost/static/__css/base.css
> <http://localhost/static/css/base.css>) it says that I don't
> have permission to access the file, same goes to media files
>
> I have followed the steps in the presentation slides
> http://code.google.com/__p/modwsgi/downloads/detail?__name=mod_wsgi-pycon-sydney-__2010.pdf
> <http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-pycon-sydney-2010.pdf> and
> made the directories accessible to others via chmod o+rx
> , my httpd.conf part is :
>
> WSGIScriptAlias / /home/loai/workspace/Faculty/__Faculty/wsgi.py
> WSGIPythonPath /home/loai/workspace/Faculty
>
> Alias /media/ /home/loai/workspace/Faculty/__Faculty/media
> Alias /static/ /home/loai/workspace/Faculty/__Faculty/static
>
> <Directory /home/loai/workspace/Faculty/__Faculty/static>
> Order deny,allow
> Allow from all
> </Directory>
>
> <Directory /home/loai/workspace/Faculty/__Faculty/media>
> Order deny,allow
> Allow from all
> </Directory>
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/L3Sm-aDXA_UJ.
>
> To post to this group, send email to django...@googlegroups.com
> <mailto:django...@googlegroups.com>.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com
> <mailto:django-users%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.

Loai Ghoraba

unread,
Nov 30, 2012, 11:57:29 PM11/30/12
to django...@googlegroups.com
thanks, but I have tried this now and it also doesn't work :X though the author slides presentation mentioned chmod o+rx on the root dir only.

On Sat, Dec 1, 2012 at 6:53 AM, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
chmod -R o+rx

Mike Dewhirst

unread,
Dec 1, 2012, 12:15:18 AM12/1/12
to django...@googlegroups.com
Here is my working apache2 conf for project "proj" on site mydomain.com.
It is running happily on Ubuntu 12.04 with permissions on all
/var/www/proj directories and files rwxrwx---

This is because I need users in the group to have access but no-one from
outside. Apache is the owner.

Good luck

Mike

# proj #########################################################

<VirtualHost *:80>

# proj resolves to lenny 109
DocumentRoot /var/www/proj/htdocs/
ServerName proj.mydomain.com
ServerAdmin webm...@mydomain.com

HostnameLookups Off
UseCanonicalName Off

ErrorLog ${APACHE_LOG_DIR}/proj-error.log
CustomLog ${APACHE_LOG_DIR}/proj-access.log combined

Alias /robots.txt /var/www/static/proj/robots/robots.txt
Alias /favicon.ico /var/www/static/proj/img/proj.ico

# lock the public out
<Directory /var/www/proj/>
AllowOverride None
Order deny,allow
Deny from all
</Directory>

# serve uploaded media from here
<Directory /var/www/media/proj/>
AllowOverride None
Order deny,allow
Allow from all
</Directory>

# serve static stuff from here
<Directory /var/www/static/proj/>
AllowOverride None
Order deny,allow
Allow from all
</Directory>

<IfModule mod_alias.c>
Alias /media/ /var/www/media/proj/
Alias /static/ /var/www/static/proj/
Alias /tiny_mce/ /var/www/static/proj/js/tiny_mce/
Alias /jquery/ /var/www/static/proj/js/jquery/
</IfModule>

<IfModule mod_wsgi.c>
WSGIScriptAlias / /var/www/proj/proj/proj.wsgi
<Directory /var/www/proj/proj/>
Order deny,allow
Allow from all
</Directory>
</IfModule>

</VirtualHost>

Loai Ghoraba

unread,
Dec 1, 2012, 12:42:33 AM12/1/12
to django...@googlegroups.com
thanks, but still I can't find what's wrong with the permission thing. The html pages are loaded without static content, no css or js or whatever, neither the media is accessible.



For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.

Loai Ghoraba

unread,
Dec 1, 2012, 1:17:44 AM12/1/12
to django...@googlegroups.com
a strange thing is that when I remove the <Files> </Files> directive so it becomes:

<Directory /home/loai/workspace/Faculty/Faculty>
Order deny,allow
Allow from all
</Directory>

instead of 

<Directory /home/loai/workspace/Faculty/Faculty>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>

then trying to access any static or media file raises (not found) instead of permission denied !

Loai Ghoraba

unread,
Dec 1, 2012, 2:48:56 AM12/1/12
to django...@googlegroups.com
okay it works now, I was just missing a trailing slash at
Alias /static/ /home/loai/workspace/Faculty/Faculty/static/

Chris Cogdon

unread,
Dec 1, 2012, 4:14:30 AM12/1/12
to django...@googlegroups.com


On Friday, November 30, 2012 8:53:42 PM UTC-8, Mike Dewhirst wrote:
On 1/12/2012 3:48pm, Loai Ghoraba wrote:
> I have ran chmod o+rx on the root directory, isn't this enough (isn't
> chmod applied to all folders down recursively ?) ?

No. You need chmod -R o+rx

Oh hell no, don't do that... that will impact the ENTIRE FILESYSTEM


Timothy Makobu

unread,
Dec 1, 2012, 4:42:43 AM12/1/12
to django...@googlegroups.com
Root directory??? As in / ? Nooo nononooooo


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/cB-WWrnMMP8J.

Loai Ghoraba

unread,
Dec 1, 2012, 6:47:39 AM12/1/12
to django...@googlegroups.com
no I mean the root of my project guys :) thanks a lot :D which lives in path/to/my/project :)

Chris Cogdon

unread,
Dec 1, 2012, 10:08:54 PM12/1/12
to django...@googlegroups.com


On Saturday, December 1, 2012 3:47:39 AM UTC-8, Loai Ghoraba wrote:
no I mean the root of my project guys :) thanks a lot :D which lives in path/to/my/project :)

Oh thank god for that!

I'd actually done something similiar once... I'd removed a bunch of permissions using chmod -R /   rather than chmod -R . ... This was on an oldold NCR Tower 32 running SVR3. I ended up writing a program to go through the archives on tape (yes, tape) and copy only the permission bits from all the tape files.

Anyway, a better form of that command is chmod -R a+rX

The capital X means "only set the execute bit if any execute bits are set". If you use lower-case x, then you'll send up setting the execute bit for normal files, too, which is another potential security risk. If you want to fix this up, do:

find . -type f -print0 | xargs -0 chmod a-x
chmod a+x manage.py # Restore x for the Django management command

Protip: always use the -print0 | xargs -0  form of the "find/xargs" pattern, as this will prevent spaces in your paths from causing havoc.

I wish I knew of a better way to set the x bits all the way up the tree, without giving someone a program to run, the best I can come up with is:

cd static
chmod a+x . .. ../.. ../../.. ../../../.. ../../../../.. ../../../../../.. ../../../../../../..

and hope that's enough :)


Loai Ghoraba

unread,
Dec 2, 2012, 2:03:51 AM12/2/12
to django...@googlegroups.com
Thanks a million for the tip :)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/_8jpEFytyesJ.

Phang Mulianto

unread,
Dec 16, 2012, 8:45:35 AM12/16/12
to django...@googlegroups.com
THank for the config , i do able to run the apache22 with mod_wsgi + python 2.7 in windows server.
Reply all
Reply to author
Forward
0 new messages