【发布时间】:2015-09-04 03:27:51
【问题描述】:
我在 /var/files 中有 2 个 html 文件:host1.html 和 host2.html。 我希望 nginx 根据 rails 响应为它们中的任何一个提供服务(作为索引文件),例如 http://localhost - 应该呈现 host1.html 或 host2.html。
这是 Rails 控制器:
class HomeController < ApplicationController
def index
response.headers['X-Accel-Redirect'] = 'host1.html'
head :ok
end
end
和 nginx 配置:
upstream app_server {
server 0.0.0.0:3000 fail_timeout=0;
}
server {
listen 8080 default;
location /{
proxy_pass http://app_server;
internal;
root /var/files/;
}
}
这不起作用。
如果删除内部 - 请求代理到 Rails,但没有发生内部重定向...
另外,我想提供的不仅仅是 html 文件——实际上是任何文件。
请指教。 谢谢。
【问题讨论】:
-
我看不到你在哪里通过你的请求 ro rails。此外,
X-Accel-Redirect标头必须以斜杠开头 (/) -
它被代理到 0.0.0.0:3000 - rails 服务器在这里运行。
-
> 必须以斜杠 (/) 开头,我都试过了。
-
"它被代理到 0.0.0.0:3000" — 我在你的配置中没有看到这个。显示真实的完整配置
-
@AlexeyTen 更新了,请看。请考虑到我是 nginx 新手。
标签: ruby-on-rails nginx