環境哈希傳遞到每一個組件堆棧中有一個SERVER_SOFTWARE
鍵。運行此並遵守網頁上的輸出:如果有rackup執行
require 'rack'
class EnvPrinter
def call env
[200, {'content-type' => 'text/plain'}, [env.inspect]]
end
end
run EnvPrinter.new
,在WEBrick將用作服務器(這是默認值),SERVER_SOFTWARE
將會像WEBrick/1.3.1 (Ruby/1.9.3/2013-01-15)
。如果使用獨角獸,它將類似Unicorn 4.5.0
。此機架代碼根據運行的服務器返回自定義響應:
require 'rack'
class EnvPrinter
def call env
response = case env.fetch('SERVER_SOFTWARE')
when /webrick/i then 'Running on webrick'
when /unicorn/i then 'Running on unicorn'
when /thin/i then 'Running on thin'
else "I don't recognize this server"
end
[200, {'content-type' => 'text/plain'}, [response]]
end
end
run EnvPrinter.new
我想知道這可能對您有所幫助。 http://stackoverflow.com/questions/7193635/change-default-server-for-rails – Vinay 2013-02-08 11:30:06