[mod_python] newb question on apache conf

Graham Dumpleton grahamd at dscpl.com.au
Fri Feb 25 16:47:59 EST 2005


On Friday, February 25, 2005, at 11:58  PM, Nicolas Lehuen wrote:

> On Fri, 25 Feb 2005 14:36:10 +0000 (GMT), lafras at sun.ac.za
> <lafras at sun.ac.za> wrote:
>> hi,
>>
>> i have the following in my apache conf file,
>>
>> <Directory "path/to/my/directory">
>>      SetHandler mod_python
>>      PythonHandler mod_python.publisher
>>      PythonDebug On
>> </Directory>
>>
>> I get some odd behaviour though,
>
> If you use the SetHandler directive, each and every request is handled
> by mod_python, which then uses mod_python.publisher to publish
> something according to the request. So with the setup you describe,
> even a request for an html page is handled by the publisher, which
> does not find anything to do with the URL it is provided.
>
> A simple solution is simply to tell Apache to use mod_python only for
> .py files ; for this you use the AddHandler directive instead of the
> SetHandler one :
>
> AddHandler mod_python .py
>
> instead of :
>
> SetHandler mod_python

Alternatively, try using:

<Directory "path/to/my/directory">
      SetHandler mod_python
      PythonHandler mod_python.publisher
      PythonDebug On
      <Files *.html>
           SetHandler None
      </Files>
</Directory>

In other words, default is to send everything through 
mod_python.publisher
but you list exceptions which you don't want to be using <Files> and
resetting the handler back to None. You may though want to do this for
all sorts of files, eg, *.jpg, *.png, *.gif etc etc, which may be more
trouble that its worth.

BTW, if you do use:

   AddHandler mod_python .py

as suggested, make sure you also specify:

   <Files *.pyc>
       deny from all
   </Files>

This will protect you from having someone grab copies of your compiled
byte code files if it so happened that Apache ran as a user which had
permission to create them. Granted that most users Apache wouldn't run
this way, but it is still a risk that I don't believe I have ever seen
mentioned before.

Graham



More information about the Mod_python mailing list