Ruby cgi需要重新加载apache以获得新值吗?

我在Ubuntu上安装了apache的phusion-passenger。 在我的config.ru中,我有以下代码:

require 'cgi' $tpl = CGI.new['myvar'] + '.rb' app = proc do |env| [200, { "Content-Type" => "text/html" }, [$tpl]] end run app 

那么当我在http://localhost/?myvar=hello访问我的浏览器时,我看到打印出来的单词hello ,这很好。 然后我将URL更改为http://localhost/?myvar=world ,但页面仍显示hello 。 只有在我重新加载apache之后页面才会显示world

在使用phusion-passenger之前,我使用mod_ruby和apache。 如果我没记错的话,我不需要重新启动apache来获取CGI变量来打印更新的值。

我并不是因为需要使用CGI。 我只是希望能够获取查询字符串参数,而无需每次都重新加载apache。

我没有使用rails或Sinatra,因为我只是试图围绕Ruby语言,以及使用apache的phusion-passenger是什么。

IMO这种行为是有道理的。 因为$tpl仅在加载文件时设置一次,所以当第一个请求被提供时会发生什么。 之后 – 在以下请求中 – 只调用proc ,但这不再改变$tpl

我不是使用普通的CGI ,而是使用一个非常简单的Rack应用程序:

 require 'rack' require 'rack/server' class Server def self.call(env) req = Rack::Request.new(env) tpl = "#{req.params['myvar']}.rb" [200, {}, [tpl]] end end run Server