【发布时间】:2015-06-09 21:35:20
【问题描述】:
我有两个应用程序:/foo 和 /bar。在每个文件夹中,我都启动了乘客。对于 foo:
passenger start -d -e production -p 4000
对于酒吧:
passenger start -d -e production -p 4001
然后我将 nginx 配置如下:
server {
listen 80 default_server;
server_name www.server.com;
root /var/www/html;
location /foo/ {
proxy_pass http://0.0.0.0:4000/;
proxy_set_header Host $host;
}
location /bar/ {
proxy_pass http://0.0.0.0:4001/;
proxy_set_header Host $host;
}
}
应用程序正在提供服务,但所有链接均无效。 users#index 操作的链接返回为 '/users' 而不是 '/foo/users'。
- 我在两个应用程序中都设置了 config.relative_url_root,这有助于资产而不是链接。
-
_url和_path方法我都试过了,都不管用。 - 这个 answer 很接近,但 passenger_base_uri 不是股票 nginx 的有效指令。
-
然后我按照 advanced configuration instructions 为乘客的 nginx 配置添加了
passenger_base_uri = '/foo';到我的自定义 conf 文件并像这样加载它:passenger start -d -e production -p 4000 --nginx-config-template nginx.conf.erb
仍然没有爱,我没有想法。有没有人这样做过?这似乎是在生产中部署多个应用的常用方法。
更多想法 (2015-06-05)
将passenger_base_uri = '/foo' 添加到我的 nginx.conf.erb 文件中将应用程序托管在两个位置(这对我来说很奇怪,但无论如何):
localhost:4000/localhost:4000/foo/
第一个没有正确的资源链接(即它只是 '/users')但可以访问其资产。
第二个有正确的资源链接(例如'/foo/users')但没有它的资产(这是因为它在其public文件夹中寻找/foo/assets/*,而不仅仅是@987654340 @)。我相信这是要走的路,因为我可以像这样更改我的代理以获取应用程序:
location /foo/ {
proxy_pass http://0.0.0.0:4000/foo/;
proxy_set_header Host $host;
}
还有其他人有什么想法吗?如果我这样做,则意味着我必须将我的资产转入 public/foo 才能正常工作。不是世界末日,但它仍然看起来很奇怪。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 nginx passenger