Apache and Django : 403 Forbidden

177 views
Skip to first unread message

Fabien Schwob

unread,
Nov 22, 2006, 2:29:56 AM11/22/06
to django...@googlegroups.com
Hello,

I've finished my app using Django, and I'm now trying to host it on a
dedicated server using Apache 2 and mod_python. But, I get a "403
Forbidden" error from Apache on nearly all pages I want to see.

The website is at the url : http://www.chibbi.fr.

The thing I don't understand, is that the main page
(http://www.chibbi.fr.) and the /chibbi/ page
(http://www.chibbi.fr/chibbi/) works, but the other no. You will see
the errors by clicking on any links.

And here is my configuration :
Apache/2.0.58 (Unix) mod_ssl/2.0.58 OpenSSL/0.9.7i mod_python/3.1.4 Python/2.4.2

The django project name is chibbi and it folder is in /home/chibbi/.

The database is MySQL.

The virtual host is the following one :

<VirtualHost *:80>
ServerName www.chibbi.fr
ServerAlias chibbi.fr

DocumentRoot /home/chibbi/
<Directory />
SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "sys.path+['/home/chibbi']"
SetEnv DJANGO_SETTINGS_MODULE chibbi.settings
PythonDebug On
</Directory>

Alias /static "/home/chibbi/chibbi/media"
<Location "/static">
SetHandler None
</Location>
</VirtualHost>

And my url.py file :
from django.conf.urls.defaults import *
from chibbi.club.feeds import LatestBlogEntries, PodCast, EventsDateFeed

feeds = {
'blog': LatestBlogEntries,
'podcast': PodCast,
'evenements': EventsDateFeed,
}


urlpatterns = patterns('',
# Example:
(r'^$', 'chibbi.club.views.index'),
(r'^static/(.*)$', 'django.views.static.serve', {'document_root':
'/home/cocoa/chibbi/media'}),
(r'^chibbi/$', 'chibbi.club.views.chibbi'),
(r'^pink-purple/$', 'chibbi.club.views.pink_purple'),
(r'^contact/$', 'chibbi.club.views.contact'),
#(r'^photos-videos/$', 'chibbi.club.views.photos_videos'),
(r'^photos-videos/(tag-(?P<tag>[a-zA-Z0-9-_]+)/)?(page-(?P<page>[0-9]+)/)?$',
'chibbi.club.views.photos'),
(r'^photos-videos/(tag-(?P<tag>[a-zA-Z0-9-_]+)/)?(page-(?P<page>[0-9]+)/)?((?:photo|video)-(?P<photo_id>[0-9]+)/)?$',
'chibbi.club.views.photos_detail'),
(r'^flux/', 'chibbi.club.views.flux'),
(r'^inscription/$', 'chibbi.club.views.register'),
(r'^blog/$', 'chibbi.club.views.blog'),
(r'^blog/(?P<title>[a-zA-Z0-9-_]+)/$', 'chibbi.club.views.blog_detail'),
(r'^traiter-inscription/$', 'chibbi.club.views.process_register'),
(r'^connexion/$', 'chibbi.club.views.login'),
(r'^deconnexion/$', 'chibbi.club.views.logout'),
(r'^evenements/$', 'chibbi.club.views.all_events'),
(r'^evenements/(?P<event>[a-zA-Z0-9-_]+)/$', 'chibbi.club.views.event'),
(r'^evenements/inscription/(?P<event>[a-zA-Z0-9-_]+)/$',
'chibbi.club.views.event_register'),
(r'^lieux/$', 'chibbi.club.views.location_all'),
(r'^lieux/filtre-(?P<filter>[a-z0-9-_]+)/$','chibbi.club.views.location_all'),
(r'^lieux/(?P<place_name>[a-zA-Z0-9-_]+)/$', 'chibbi.club.views.location'),

(r'^profil/$', 'chibbi.club.views.profil'),
(r'^profil/editer/$', 'chibbi.club.views.edit_profil'),
(r'^profil/password/','chibbi.club.views.edit_password'),
(r'^profil/messages/$', 'chibbi.club.views.profil_messages'),
(r'^profil/messages/(?P<id_message>[0-9]+)/$',
'chibbi.club.views.view_message'),

(r'^clubbers/((?P<filtre>[a-zA-Z0-9-_]+)/)?$', 'chibbi.club.views.clubber'),
(r'^clubber/(?P<clubber_login>[a-zA-Z0-9-_.]+)/$','chibbi.club.views.clubber_details'),
(r'^clubber/(?P<clubber_login>[a-zA-Z0-9-_.]+)/ecrire/$',
'chibbi.club.views.write_messages'),

# Newsletter
(r'^newsletter/desinscription/(?P<type>(clubber|contact))/(?P<hash>[^/]+)/',
'chibbi.club.views.newsletter_unsubscribe'),

# Uncomment this for admin:
(r'^admin/', include('django.contrib.admin.urls')),

# RSS
(r'^rss/(?P<url>.*)/$', 'django.contrib.syndication.views.feed',
{'feed_dict': feeds}),

# XML
(r'^playlist/$', 'chibbi.club.views.playlist'),

)

Does anyone have an idea on how to solve that problem ?

Thanks in advance.

--
Fabien SCHWOB
_____________________________________________________________
Derrière chaque bogue, il y a un développeur, un homme qui s'est trompé.
(Bon, OK, parfois ils s'y mettent à plusieurs).

Karsten W. Rohrbach

unread,
Nov 22, 2006, 5:18:58 AM11/22/06
to Django users

On Nov 22, 8:29 am, "Fabien Schwob" <xphut...@gmail.com> wrote:
> <Directory />
> SetHandler python-program
> PythonHandler django.core.handlers.modpython
> PythonPath "sys.path+['/home/chibbi']"
> SetEnv DJANGO_SETTINGS_MODULE chibbi.settings
> PythonDebug On
> </Directory>

Shouldn't this read <Location "/">...</Location>?

The difference is explained in these two documents:
http://httpd.apache.org/docs/2.0/mod/core.html#location
http://httpd.apache.org/docs/2.0/sections.html#file-and-web

Cheers,
/k

Fabien Schwob

unread,
Nov 22, 2006, 7:46:56 AM11/22/06
to django...@googlegroups.com

I've change my configuration to :

ServerName www.chibbi.fr
ServerAlias chibbi.fr

DocumentRoot /home/chibbi/
<Location "/">


SetHandler python-program
PythonHandler django.core.handlers.modpython
PythonPath "sys.path+['/home/chibbi']"
SetEnv DJANGO_SETTINGS_MODULE chibbi.settings
PythonDebug On

</Location>

Alias /static "/home/chibbi/chibbi/media"
<Location "/static">
SetHandler None
</Location>

But I still have the same problem.

Karsten W. Rohrbach

unread,
Nov 22, 2006, 8:56:46 AM11/22/06
to Django users
Duh!
You probably want to take out the <Location> bits for the "/"
namespace, and configure the PythonHandler for the complete
VirtualHost. (Just remove the <Location "/"> and </Location> lines).

Also, your DocumentRoot should not be the same as your python code
base, I think. At least this is what the manual recommends...

Note to self: Don't write on mailing lists before first coffee :) Sorry
for the hassle.

Cheers,
/k

Fabien Schwob

unread,
Nov 23, 2006, 7:28:22 AM11/23/06
to django...@googlegroups.com
On 11/22/06, Karsten W. Rohrbach <kar...@rohrbach.de> wrote:
> Duh!
> You probably want to take out the <Location> bits for the "/"
> namespace, and configure the PythonHandler for the complete
> VirtualHost. (Just remove the <Location "/"> and </Location> lines).
>
> Also, your DocumentRoot should not be the same as your python code
> base, I think. At least this is what the manual recommends...

Thanks, it was a problem with de DocumentRoot.

Now, I've a problem with the current directory. When I try to open
files using a relative path, I get an IOError like on
http://chibbi.fr/photos-videos/photo-270/.
All the files I would like to access are in /home/chibbi/chibbi/media.

It seems that changing the current directory (with
os.chdir('/home/chibbi/chibbi/')) it work, but I make the project
dependant of the disk structure. I there a way to say to Django to use
the project root (/home/chibbi/chibbi/ in my case).

Is there a way to change that ? I haven't found anything in the
settings.py options.

Thanks in advance.

Fabien Schwob

unread,
Nov 24, 2006, 2:24:59 AM11/24/06
to django...@googlegroups.com
> > You probably want to take out the <Location> bits for the "/"
> > namespace, and configure the PythonHandler for the complete
> > VirtualHost. (Just remove the <Location "/"> and </Location> lines).
> >
> > Also, your DocumentRoot should not be the same as your python code
> > base, I think. At least this is what the manual recommends...
>
> Thanks, it was a problem with de DocumentRoot.
>
> Now, I've a problem with the current directory. When I try to open
> files using a relative path, I get an IOError like on
> http://chibbi.fr/photos-videos/photo-270/.
> All the files I would like to access are in /home/chibbi/chibbi/media.
>
> It seems that changing the current directory (with
> os.chdir('/home/chibbi/chibbi/')) it work, but I make the project
> dependant of the disk structure. I there a way to say to Django to use
> the project root (/home/chibbi/chibbi/ in my case).

It seems that using os.chdir('/home/chibbi/chibbi/') in urls.py don't
work as expected. It works nearly all the time, and it shows only
randomly an error. I think it's when Apache is creating a new child
process which doesn't had the current directory set to
/home/chibbi/chibbi/.

Reply all
Reply to author
Forward
0 new messages