问题描述
我想通过 CGI 在 Apache 中使用 Ruby.我的配置文件中有以下内容:
I want to use Ruby in Apache through CGI. I have the following in my configuration file:
DocumentRoot /home/ceriak/ruby
<Directory /home/ceriak/ruby>
Options +ExecCGI
AddHandler cgi-script .rb
</Directory>
test.rb
是放在 /home/ceriak/ruby/
下的测试文件,#!/usr/bin/ruby
包含在第一行并赋予可执行权限.尽管如此,当我访问 localhost/test.rb
时,我会得到一个下载窗口并可以获得源代码.
test.rb
is a testfile placed under /home/ceriak/ruby/
, #!/usr/bin/ruby
included on the first line and given executable permissions. Still, when I visit localhost/test.rb
I get a download window and can obtain the source code.
有趣的是,当我将相同的脚本放在 /usr/lib/cgi-bin/
下并调用 localhost/cgi-bin/test.rb
时,它按预期工作.
Interestingly, when I place the same script under /usr/lib/cgi-bin/
and call localhost/cgi-bin/test.rb
it works as supposed.
(Ubuntu 9.10 上的 Apache2.)
(Apache2 on Ubuntu 9.10.)
有什么想法吗?
推荐答案
需要检查的事项:
- 你的文件是否可执行?您可以通过
chmod +x/path/to/file
使其可执行 - 您是否输出了正确的 Content-type?
- 标题和输出之间是否有一个空白的换行符?
- 您是否在设置完配置后重新启动了 Apache?
如果你这样做了,它应该可以正常工作.我有这个作为我的 test.rb 文件:
If you did all that, it should work fine. I have this as my test.rb file:
#!/usr/bin/env ruby
puts <<EOS
Content-type: text/html
<html><body>hi</body></html>
EOS
这篇关于在 Apache 中设置 Ruby CGI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!