2

我在一个场景中苦苦挣扎,我有几个应用程序要在单个 TorqueBox 实例上运行。定义应用程序并将其部署到应用程序内的根(“/”)上下文config/torquebox.yml时,可以正常执行,没有明显问题。起初我认为这是 Apache 反向代理的问题,但现在认为这可能是 Rails 和/或 TorqueBox 的问题,但我找不到明确的答案或问题的原因。

此配置如下:

config/torquebox.yml包含:

web:
  context: /

Apache 的代理 httpd 虚拟主机配置是:

ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

有了这个我可以访问http://sub.domain.tld/,postsposts/new路线就好了。这是通过大致遵循此处的示例 (我执行的唯一修改是使反向代理工作的修改)。

但是当我换档并在上下文中运行它时,torquebox_test_rails_production事情开始变得非常奇怪。我不得不相信,由于某种原因,rails 会将上下文的副本附加到路径上,这是有问题的。解释:

config/torquebox.yml改为:

web:
  context: /torquebox_test_rails_production

和 Apache 的 httpd 虚拟主机配置:

ProxyPass / http://127.0.0.1:8080/torquebox_test_rails_production/
ProxyPassReverse / http://127.0.0.1:8080/torquebox_test_rails_production/

当我这样做时,http://sub.domain.tld/仍然可以正常加载,但是当我转到时posts,我注意到(在log/production.log)失败的 GET 请求:

INFO -- : Started GET "/torquebox_test_rails_production/torquebox_test_rails_production/stylesheets/application.css"
FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/torquebox_test_rails_production/stylesheets/application.css"):
  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'

如您所见,它复制了路径上的上下文。

此时 URL 仍然是正确的http://sub.domain.tld/posts,但是当我在脚手架测试中单击“新帖子”时,应用程序会尝试将浏览器重定向到 http://sub.domain.tld/torquebox_test_rails_production/posts/new. 显然这种重定向/重复不应该发生。在日志中,我现在看到:

INFO -- : Started GET "/torquebox_test_rails_production/torquebox_test_rails_production/posts/new"
FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/torquebox_test_rails_production/posts/new"):
  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'

我在这里尝试的另一件事是添加config.relative_url_root到配置中。我通过尝试以下环境变量来做到这一点:

RAILS_RELATIVE_URL_ROOT="/torquebox_test_rails_production"

并将其设置config/environments/production.rb为:

config.relative_url_root = "/torquebox_test_rails_production"

我认为这应该通过上下文设置自行设置,因此它的目的是,但我认为值得一试。

我还从这个似乎与我的相同的问题中得到了提示,但是从主机名中删除contexttorquebox.yml仅使用主机名也不能解决问题。相反,它似乎已经消除了路径上下文的加倍,但我最终仍然出现以下错误log/production.log

INFO -- : Started GET "/torquebox_test_rails_production/posts"
FATAL -- : 
ActionController::RoutingError (No route matches [GET] "/torquebox_test_rails_production/posts"):
  actionpack (4.1.1) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.1.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.1.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.1.1) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.1.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
  rack (1.5.2) lib/rack/runtime.rb:17:in `call'
  rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
  railties (4.1.1) lib/rails/engine.rb:514:in `call'
  railties (4.1.1) lib/rails/application.rb:144:in `call'

然后,我还尝试如前所述定义config.relative_url_rootin ,其结果与刚刚提到的错误完全相同。production.rb

关于这里可能发生什么来引发这种行为的任何想法?

4

2 回答 2

1

我没有方便测试的 Apache 配置,但是您是否在 ProxyPass 和 ProxyPassReverse 中有一个斜杠,但在您的 Torquebox.yml 的 Web 上下文中没有?

所以而不是

ProxyPass / http://127.0.0.1:8080/torquebox_test_rails_production/
ProxyPassReverse / http://127.0.0.1:8080/torquebox_test_rails_production/

尝试

ProxyPass / http://127.0.0.1:8080/torquebox_test_rails_production
ProxyPassReverse / http://127.0.0.1:8080/torquebox_test_rails_production
于 2014-06-13T23:53:38.933 回答
1

这里的解决方案是我需要将根上下文(“/”)与主机定义一起使用,然后从 mod_proxy 配置中删除上下文。

因此,最后,起作用的是config/torquebox.yml

web:
  context: /
  host: sub.domain.tld

以及虚拟主机的 httpd mod_proxy 部分中的以下内容:

<Location />
    ProxyPass http://127.0.0.1:8080/
    ProxyPassReverse http://127.0.0.1:8080/
</Location>
于 2014-06-16T14:24:30.697 回答