How to run a simple ruby script in any web server (Apache or Mongrel or any thing else)

前端 未结 7 866
半阙折子戏
半阙折子戏 2021-02-05 06:20

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?

However, I am new to

相关标签:
7条回答
  • 2021-02-05 07:11

    Sinatra is probably your best bet for getting a Ruby script running from a web server without Rails.

    Take a look here: http://www.sinatrarb.com

    From the Sinatra docs:

    require 'sinatra'
    
    get '/hi' do
      "Hello World!"
    end
    

    Then, just run:

    $ gem install sinatra
    $ ruby -rubygems hi.rb
    == Sinatra has taken the stage ...
    >> Listening on 0.0.0.0:4567
    

    Just go to http://0.0.0.0:4567 in your browser and you should find your "Hello World"

    ...

    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-a-k-a-mod_rack/ and http://www.giantflyingsaucer.com/blog/?p=1716

    Nginx: http://tommy.chheng.com/2009/06/09/deploying-a-sinatra-app-on-nginx-passenger-with-capistrano-and-git/

    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.

    0 讨论(0)
提交回复
热议问题