如何在任何 Web 服务器(Apache 或 Mongrel 或其他任何东西)中运行简单的 ruby 脚本 [英] How to run a simple ruby script in any web server (Apache or Mongrel or any thing else)
问题描述
当我搜索与 ruby 相关的内容时,所有与 ruby on rails 相关的结果都弹出,这对我来说似乎很有趣.所以没有人再使用生红宝石了吗?
It seems very funny to me that when I search something related ruby, all ruby on rails related results popped up. So nobody using raw ruby anymore?
但是,我是 ruby 的新手.今天早上我只是想在 web 服务器中运行一个简单的 hello world ruby 脚本,首先是 apache 2,然后尝试了 mongrel.但不幸的是我失败了.我尽我所能用谷歌搜索,但结果只显示关于 ruby on rails.那么真的有什么方法可以在任何网络服务器中运行 ruby 脚本,或者即使我只想做一个 hello world 应用程序也必须使用 ror?
However, I am new to ruby. This morning I was only trying to run a simple hello world ruby script in web server, firstly apache 2 and then tried the mongrel. But unfortunately I failed. I googled every way I can, but result only shows regarding ruby on rails. So really is there any way to run a ruby script in any web server, or I have to use ror even if I just want to do a hello world application?
推荐答案
Sinatra 可能是让 Ruby 脚本从没有 Rails 的 Web 服务器运行的最佳选择.
Sinatra is probably your best bet for getting a Ruby script running from a web server without Rails.
来自 Sinatra 文档:
From the Sinatra docs:
require 'sinatra'
get '/hi' do
"Hello World!"
end
然后,运行:
$ gem install sinatra
$ ruby -rubygems hi.rb
== Sinatra has taken the stage ...
>> Listening on 0.0.0.0:4567
只需在浏览器中转到 http://0.0.0.0:4567 即可找到您好世界"
Just go to http://0.0.0.0:4567 in your browser and you should find your "Hello World"
...
此外,由于您还询问在 Apache 或其他 Web 服务器中运行的问题,您可能需要查看这些关于将新的基于 Sinatra 的应用程序部署到 Apache 或 Nginx 的教程:
To add on to this, since you also ask about running in Apache or other web servers, you may want to check out these tutorials about deploying your new Sinatra-based application to Apache or Nginx:
Apache:http://www.pastbedti.me/2009/11/deploying-a-sinatra-app-with-apache-and-phusion-passenger-aka-mod_rack/ 和 http://www.giantflyingsaucer.com/blog/?p=1716
请注意,这两个教程都涵盖了通过Passenger 运行Sinatra (http://www.modrails.com/ --不要被modrails"这个名字所拖延 :) ),我在 Apache 和 Nginx 下部署应用程序时很幸运.
Note both tutorials cover running Sinatra via Passenger (http://www.modrails.com/ -- don't be put off by the "modrails" name :) ), which I have had good luck with in deploying apps under Apache and Nginx.
这篇关于如何在任何 Web 服务器(Apache 或 Mongrel 或其他任何东西)中运行简单的 ruby 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!