有没有办法回退 nginx proxy_pass 如果 header 设置

is there a way to fallback nginx proxy_pass if header set

nginx 服务器服务 http://server1.com, http://server2.com and http://server3.com

nginx 上游请求处理某些 ruby 代码。

server1.com、server2.com和server3.com实际上是存储在amazon s3上的一些静态文件。

我接下来要做的是:找到 'server1' 主机的存储桶名称,将一些日志放入数据库并通知 nginx 从亚马逊流式传输。 也许通过在 ruby 代码 header 中设置 url 到 amazon s3 存储桶并稍后由 nginx 使用此 url。

流程:浏览器 -> nginx -> ruby -> nginx -> amazon_s3 -> 浏览器

我发现如何在出错时执行此操作:

http {
  server {
     listen 12345; #Port that my custom app was assigned
     server_name mydomain.com;

     location / {
       proxy_intercept_errors on;
       error_page 400 403 502 503 504 = @fallback;
       proxy_pass http://the_old_site_domain.com;      
     }

     location @fallback {
       proxy_pass http://myfallback.domain.com;
     }
  }
}

但是有没有办法根据 header 外表做类似的事情?

谢谢!

更新 这就是我如何测试我的 header:

if ($http_x_custom_header) {
  ....
}

如果设置 nginx 应该做一些内部重定向,对吗?

但是如何在ruby代码之后调用它?

有一个特殊的 headers 叫做 X-Accel-...。 你需要 X-Accel-Redirect.