gpt4 book ai didi

ruby-on-rails - 使用 Apache ReverseProxy 在 TorqueBox 上的 Rails 应用程序路径中复制上下文

转载 作者:太空宇宙 更新时间:2023-11-03 16:01:22 26 4
gpt4 key购买 nike

我正在努力应对这样一种情况:我有多个应用程序要在单个 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 路由就好了。这是通过大致遵循the example here (只有我执行的修改才能使反向代理工作)。

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

我将 config/torquebox.yml 更改为:

web:
context: /torquebox_test_rails_production

和 Apache 的 httpd 虚拟主机 conf 到:

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 添加到配置中。我通过尝试以下 env 变量来做到这一点:

RAILS_RELATIVE_URL_ROOT="/torquebox_test_rails_production"

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

config.relative_url_root = "/torquebox_test_rails_production"

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

我也从 this question 得到了启发这似乎与我的相同,但是从 torquebox.yml 中删除 context 并且仅拥有主机名也没有解决问题。相反,它似乎已经消除了路径上下文的加倍,但我最终在 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'

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

知道这里可能发生什么来引发这种行为吗?

最佳答案

我手头没有可供测试的 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

关于ruby-on-rails - 使用 Apache ReverseProxy 在 TorqueBox 上的 Rails 应用程序路径中复制上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24214995/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com