配置文件test.conf如下:
<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>
然后我运行Ocsigen:
ocsigeocsigen-c测试.conf
我可以参观http://127.0.0.1:8000/qachina/index.htm.然而,Ocsigen并没有在cgi-bin中执行我的python脚本,而是希望浏览器下载它
顺便说一句,所有python脚本文件都可以直接在shell中运行。
>head cgi-bin/nav.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-enter code here
...
我无法访问Ocsigen的邮件列表,所以我在这里发帖寻求建议。
对于站点上的每个请求,Ocsigen都会尝试按配置文件的顺序列出的扩展名。在您的情况下,它会尝试staticmod,这是成功的,因为cgi-bin是一个存在于指定给staticmod的目录中的目录。如果您希望首先尝试cgimod,则应将<cgi ...>
放在<static ...>
之前。
您的Ocsigen版本究竟是什么?
我刚刚尝试了ocsigen 1.3.4(目前正在Debian测试中的版本(,您的配置片段似乎有一个错误(在ocsigen方面(。你想要的可以通过实现
<cgi regexp="cgi-bin/([^/]*)" dir="/usr/lib/cgi-bin/" script="1" />
我刚刚检查了我可以访问的所有正在运行的Ocsigen实例,它们都使用了"regexp"属性。不过,文档确实允许您的版本,服务器也接受它。这两种选择之一就是bug。
仅供参考,使用-V
选项运行ocsigen会有所帮助。
我不知道任何确切的答案,因为在我看来它应该有效,但我确实有一些问题可能会有所帮助。
当你收到下载提示时,你真的下载了吗?如果是,您是在下载脚本产生的网页,还是在下载脚本本身?如果是前者,那么这只是某种mime类型的问题。如果是后者,听起来更可能是为页面服务的静态模块的问题,而不是CGI模块的问题。您是否尝试删除<static dir="/media/E/www/qachina" />
以查看这是否有冲突?
>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)
访问时http://localhost:8000/qachina/cgi-bin/nav.py使用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:Ocsigen_http_com。Connection_closed(发送500(->发送500…
在将每个python文件的#!/usr/bin/env python
更改为#!/usr/local/bin/python
之后,现在似乎可以工作了!
谢谢!