Q: Why can't Ocsigen run my python file? The configure file test.conf is as below:
<ocsigen>
<server>
<port>*:8000</port>

<logdir>/home/zaxis/tmp/log/</logdir>
<datadir>/home/zaxis/tmp/data</datadir>
<user>zaxis</user>
<group>wheel</group>
<charset>utf-8</charset>
......
<extension findlib-package="ocsigen_ext.cgimod">
  <cgitimeout value="30"/>
</extension>

<extension findlib-package="ocsigen_ext.staticmod"/>
......
<site path="qachina" charset="utf-8">
    <cgi root="cgi-bin" dir="/media/E/www/qachina/cgi-bin"/>
    <static dir="/media/E/www/qachina" />
</site>
....
<commandpipe>/home/zaxis/tmp/ocsigen_command</commandpipe>
</server>
</ocsigen>

Then I run Ocsigen:

ocsigeocsigen -c test.conf

I can visit http://127.0.0.1:8000/qachina/index.htm. However, Ocsigen does not execute my python script in cgi-bin but wants the browser to download it.
BTW, all python script files can be run in the shell directly.
>head cgi-bin/nav.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-enter code here
...

I cannot visit Ocsigen's mailing list, so I'm posting here for suggestions.

A: For each request on a site, Ocsigen tries the extensions listed in the order of the configuration file. In your case, it tries staticmod, which succeeds, since cgi-bin is a directory existing in the directory given to staticmod. If you want cgimod to be tried first, you should put <cgi ...> before <static ...>.

A: What is exactly your Ocsigen version?
I've just tried with ocsigen 1.3.4 (the version currently in Debian testing), and there seems to be a bug (on the Ocsigen side) with your configuration snippet. What you want can be achieved with:
<cgi regexp="cgi-bin/([^/]*)" dir="/usr/lib/cgi-bin/" script="\1" />

I've just checked on all running instances of Ocsigen that I have access to, and they all use the "regexp" attribute. The documentation does allow your version, though, and the server accepts it. One of these two alternatives is a bug.
FYI, running ocsigen with the -V option helped.

A: I don't know any solid answer, because it looks to me like it ought to work, but I do have some questions that might be helpful.
When you get prompted to download, have you actually downloaded it?  If so, are you downloading the web page which would result from the script or are you downloading the script itself?  If it's the former, then it's just a mime-type issue of some sort.  If it's the later, it sounds more likely to be a problem with the static module serving the page rather than the CGI one.  Have you tried removing the <static dir="/media/E/www/qachina" /> to see if this is conflicting?

A: >cat /usr/ports/www/ocsigen/Makefile |grep -i version 
PORTVERSION=    1.1.0
>ocsigen -c test.conf -V
[warnings.log] 2011-11-28 08:25:47 - Exception while creating IPv6 socket: Invalid argument in function bind ()
-- Dependencies of ocsigen_ext.redirectmod: ocsigen_ext.redirectmod
-- Needed: /usr/local/lib/ocsigen/extensions/redirectmod.cmo
Loading extension /usr/local/lib/ocsigen/extensions/redirectmod.cmo
-- Dependencies of ocsigen_ext.cgimod: ocsigen_ext.cgimod
-- Needed: /usr/local/lib/ocsigen/extensions/cgimod.cmo
Loading extension /usr/local/lib/ocsigen/extensions/cgimod.cmo
-- Dependencies of ocsigen_ext.staticmod: ocsigen_ext.staticmod
-- Needed: /usr/local/lib/ocsigen/extensions/staticmod.cmo
Loading extension /usr/local/lib/ocsigen/extensions/staticmod.cmo
-- Dependencies of ocsigen_ext.ocsipersist-sqlite: sqlite3, ocsigen_ext.ocsipersist sqlite
-- Needed: /usr/local/lib/ocaml/site-lib/sqlite3/sqlite3.cma, /usr/local/lib/ocsigen/   extensions/ocsipersist-sqlite.cma
Loading extension /usr/local/lib/ocaml/site-lib/sqlite3/sqlite3.cma
Loading extension /usr/local/lib/ocsigen/extensions/ocsipersist-sqlite.cma
-- Dependencies of ocsigen_ext.eliom: num.core, num, cryptokit, ocsigen_ext.eliom
-- Needed: /usr/local/lib/ocaml/nums.cma, /usr/local/lib/ocaml/site-lib/cryptokit cryptokit.cma, /usr/local/lib/ocsigen/extensions/eliom.cma
Loading extension /usr/local/lib/ocaml/nums.cma
Loading extension /usr/local/lib/ocaml/site-lib/cryptokit/cryptokit.cma
Loading extension /usr/local/lib/ocsigen/extensions/eliom.cma
[warnings.log] 2011-11-28 08:25:47 - While parsing config file, tag <host>: Assuming defaulthostname is "localhost"
-- Dependencies of eliom_examples.miniwiki: eliom_examples.miniwiki
-- Needed: /usr/local/lib/ocsigen/examples/miniwiki.cmo
Loading /usr/local/lib/ocsigen/examples/miniwiki.cmo (will be reloaded every times)
-- Dependencies of eliom_examples.tutoeliom: eliom_examples.tutoeliom
-- Needed: /usr/local/lib/ocsigen/examples/tutoeliom.cmo
Loading /usr/local/lib/ocsigen/examples/tutoeliom.cmo (will be reloaded every times)
[warnings.log] 2011-11-28 08:25:47 - Reloading config file
...
[warnings.log] 2011-11-28 08:25:47 - Config file reloaded
[warnings.log] 2011-11-28 08:25:47 - Ocsigen has been launched (initialisations ok)

When visiting http://localhost:8000/qachina/cgi-bin/nav.py using Opera:
GET /qachina/cgi-bin/nav.py HTTP/1.1
User-Agent: Opera/9.80 (X11; FreeBSD 8.2-RELEASE i386; U; zh-cn) Presto/2.9.168 Version/11.50
Host: localhost:8000
Accept: text/html, application/xml;q=0.9, application/xhtml+xml, image/png, image/webp, image/jpeg, image/gif, image/x-xbitmap, */*;q=0.1
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8
Accept-Encoding: gzip, deflate
Cache-Control: no-cache
Connection: Keep-Alive

- host=localhost
[access.log] 2011-11-28 08:42:06 - connection for localhost from 127.0.0.1 (Opera/9.80 (X11; FreeBSD 8.2-RELEASE i386; U; zh-cn) Presto/2.9.168 Version/11.50): /qachina/cgi-bin/nav.py
-------- host found! localhost:8000 matches * 
site "ocsigenstuff" does not match url "qachina/cgi-bin/nav.py".
site "miniwiki" does not match url "qachina/cgi-bin/nav.py".
-------- site found: url "qachina/cgi-bin/nav.py" matches "qachina".
--Cgimod: Is it a cgi file?
--Cgimod: Testing "/media/E/www/qachina/cgi-bin/nav.py".
--Cgimod: Looking for "/media/E/www/qachina/cgi-bin/nav.py".
** Receiving HTTP message
[warnings.log] 2011-11-28 08:42:06 - CGI says: env: python: No such file or directory
Thread 10 killed on uncaught exception Invalid_argument("index out of bounds")
[warnings.log] 2011-11-28 08:42:06 - CGI exited with code 127
~~~ Exception during generation/sending: Ocsigen_http_com.Connection_closed

[warnings.log] 2011-11-28 08:42:06 - Exn during page generation: Ocsigen_http_com.Connection_closed (sending 500)
    -> Sending 500
    ...
After changing #!/usr/bin/env python to #!/usr/local/bin/python for each python file, it seems to work now!
thanks!
