在Apache中设置红宝石CGI [英] Setting up Ruby CGI in Apache
问题描述
我想通过CGI使用Ruby在Apache中。我在我的配置文件中的以下内容:
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
正在放在testfile的的/ home / ceriak /红宝石/
,#!的/ usr / bin中/红宝石
包含在第一行,并给予可执行权限。不过,当我访问本地主机/ test.rb
我得到一个下载窗口,可以获取源$ C $ C。
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目录/
并调用本地主机/ cgi-bin目录/测试相同的脚本。 RB
它的工作原理像预想的那样。
Interestingly, when I place the same script under /usr/lib/cgi-bin/
and call localhost/cgi-bin/test.rb
it works as supposed.
(Apache2的在Ubuntu 9.10)。
(Apache2 on Ubuntu 9.10.)
任何想法?
推荐答案
几件事情要检查:
- 是您的文件的可执行文件?你可以把它可执行转到
使用chmod + X /路径/要/文件
- 你输出正确的内容类型?
- 有你的头,你的输出之间的空白换行符?
- 你将配置后,重新启动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中设置红宝石CGI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!