如何让独角兽在路径下运行 Rails 3.0 应用程序? [英] How to make unicorn run a Rails 3.0 app under a path?

查看:35
本文介绍了如何让独角兽在路径下运行 Rails 3.0 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从Passenger 迁移到Unicorn,我曾经使用Passenger 运行我的Rails 3.0 应用程序,并使用RailsBaseURI 选项来为所有URL 加上前缀/blah".

I'm migrating from Passenger to Unicorn, and with Passenger I used to run my Rails 3.0 app with the RailsBaseURI option to prefix all URLs with '/blah' for example.

在 Unicorn 下运行相同的应用程序时,我将 '--path/blah' 传递给 unicorn_rails,但服务器仍然作为 http://server:3000/etc/etc,而不是 http://server:3000/blah/etc/etc - 我看到一些资产是通过/blah/请求的(比如 JS 文件等等),但是各种链接之前仍然没有/blah/".

When running the same app under Unicorn, I pass '--path /blah' to unicorn_rails, but the server still serves things as http://server:3000/etc/etc, instead of http://server:3000/blah/etc/etc - I see some assets being requested via /blah/ (like JS files, and so on), but the various links still do not have '/blah/' before them.

所以 - 总结一下 - 我如何让 Unicorn 将我的应用程序安装在/blah 下,以便所有请求都使用预先添加到路径的/blah",并且所有链接和资产都使用预先添加到的/blah/"创建他们?

So - to summarise - how to I get Unicorn to mount my app under /blah, so that all requests work with '/blah' prepended to the path and all links and assets are created with '/blah/' prepended to them?

谢谢

推荐答案

这是我的发现:

要让 Rails 应用提供资源和链接 URL,您必须在启动前设置环境变量:

To get a Rails app to serve asset and link URLs, you have to set an environment variable before it starts:

ENV['RAILS_RELATIVE_URL_ROOT'] = '/prefix'

然后,正如@d11wtq 所说,要让 Rack 兼容服务器(在本例中为 Unicorn)以前缀实际服务应用程序,您必须在 config.ru 文件中,而不是通常的运行行,请执行以下操作:

Then, as @d11wtq said, to get the Rack-compatible server (in this case, Unicorn) to actually serve the app under a prefix, you have to, in your config.ru file, instead of the usual run line, do the following:

run Rack::URLMap.new(
  ENV['RAILS_RELATIVE_URL_ROOT'] => Rails.application
)

这篇关于如何让独角兽在路径下运行 Rails 3.0 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆